Browse Source

hold back on the merge changes because this isn't quite right yet

Simon Krajewski 5 years ago
parent
commit
ffdb56041b

+ 3 - 3
src/context/typecore.ml

@@ -550,9 +550,9 @@ let spawn_constrained_monos ctx p map params =
 	check_constraints map params monos p;
 	monos
 
-let safe_mono_close ctx m mode p =
+let safe_mono_close ctx m p =
 	try
-		Monomorph.close m mode
+		Monomorph.close m
 	with
 		Unify_error l ->
 			raise_or_display ctx l p;
@@ -562,7 +562,7 @@ let with_contextual_monos ctx f =
 	let old_monos = ctx.monomorphs.percall in
 	ctx.monomorphs.percall <- [];
 	let r = f() in
-	List.iter (fun (m,p) -> ignore(safe_mono_close ctx m CContextual p)) ctx.monomorphs.percall;
+	(* List.iter (fun (m,p) -> ignore(safe_mono_close ctx m p)) ctx.monomorphs.percall; *)
 	ctx.monomorphs.percall <- old_monos;
 	r
 

+ 3 - 7
src/core/tUnification.ml

@@ -61,10 +61,6 @@ module Monomorph = struct
 		| CStructural of (string,tclass_field) PMap.t * bool
 		| CTypes of (t * string option) list
 
-	type closing_mode =
-		| CContextual
-		| CRequired
-
 	(* constraining *)
 
 	let add_constraint m constr =
@@ -137,7 +133,7 @@ module Monomorph = struct
 			(* If we assign an open structure monomorph to another structure, the semantics want us to merge the
 			   fields. This is kinda weird, but that's how it has always worked. *)
 			constrain_to_type m None t;
-			ignore(close m CContextual)
+			ignore(close m)
 		| TMono m2 ->
 			begin match m2.tm_type with
 			| None ->
@@ -151,13 +147,13 @@ module Monomorph = struct
 			do_bind m t
 		end
 
-	and close m mode = match m.tm_type with
+	and close m = match m.tm_type with
 		| Some _ ->
 			false
 		| None -> match classify_constraints m with
 			| CUnknown ->
 				false
-			| CTypes [(t,_)] when mode = CRequired ->
+			| CTypes [(t,_)] ->
 				do_bind m t;
 				true
 			| CTypes _ ->

+ 1 - 1
src/typing/generic.ml

@@ -50,7 +50,7 @@ let make_generic ctx ps pt p =
 				| _ when not top ->
 					follow_or t top (fun() -> "_") (* allow unknown/incompatible types as type parameters to retain old behavior *)
 				| TMono ({ tm_type = None } as m) ->
-					if safe_mono_close ctx m CRequired p then loop top t
+					if safe_mono_close ctx m p then loop top t
 					else raise (Generic_Exception (("Could not determine type for parameter " ^ s), p))
 				| TDynamic _ -> "Dynamic"
 				| t ->

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -224,7 +224,7 @@ let type_function ctx args ret fmode f do_display p =
 		| _ -> e
 	in
 	List.iter (fun r -> r := Closed) ctx.opened;
-	List.iter (fun (m,p) -> ignore(safe_mono_close ctx m CRequired p)) ctx.monomorphs.perfunction;
+	List.iter (fun (m,p) -> ignore(safe_mono_close ctx m p)) ctx.monomorphs.perfunction;
 	if is_position_debug then print_endline ("typing:\n" ^ (Texpr.dump_with_pos "" e));
 	e , fargs
 

+ 12 - 0
tests/unit/src/unit/TestConstrainedMonomorphs.hx

@@ -60,6 +60,18 @@ class TestConstrainedMonomorphs extends Test {
 	}
 	function testMergedConstraints() {
 		var a = merge({foo: 5}, {bar: "bar"});
+		#if todo
 		HelperMacros.typedAs(a, (null : { foo: Int, bar: String }));
+		#end
+		Assert.pass();
 	}
+
+	public static function returnC<C:{foo:Int}>():C {
+		return notMerge();
+	}
+
+	public static function notMerge<C:{foo:Int}>():C {
+		return null;
+	}
+
 }