Browse Source

[typer] add `pf_supports_function_equality`

see #6705
Simon Krajewski 7 years ago
parent
commit
0e357485b6
2 changed files with 10 additions and 0 deletions
  1. 3 0
      src/context/common.ml
  2. 7 0
      src/typing/typer.ml

+ 3 - 0
src/context/common.ml

@@ -94,6 +94,8 @@ type platform_config = {
 	pf_can_skip_non_nullable_argument : bool;
 	(** type paths that are reserved on the platform *)
 	pf_reserved_type_paths : path list;
+	(** supports function == function **)
+	pf_supports_function_equality : bool;
 }
 
 type compiler_callback = {
@@ -235,6 +237,7 @@ let default_config =
 		pf_overload = false;
 		pf_can_skip_non_nullable_argument = true;
 		pf_reserved_type_paths = [];
+		pf_supports_function_equality = true;
 	}
 
 let get_config com =

+ 7 - 0
src/typing/typer.ml

@@ -833,6 +833,13 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 		with Error (Unify _,_) ->
 			e1,AbstractCast.cast_or_unify ctx e1.etype e2 p
 		in
+		if not ctx.com.config.pf_supports_function_equality then begin match e1.eexpr, e2.eexpr with
+		| TConst TNull , _ | _ , TConst TNull -> ()
+		| _ ->
+			match follow e1.etype, follow e2.etype with
+			| TFun _ , _ | _, TFun _ -> ctx.com.warning "Comparison of function values is unspecified on this target, use Reflect.compareMethods instead" p
+			| _ -> ()
+		end;
 		mk_op e1 e2 ctx.t.tbool
 	| OpGt
 	| OpGte