Browse Source

[typer] fix empty structure constraint handling differently

closes #9593
Simon Krajewski 5 years ago
parent
commit
1e8df1ed3b
2 changed files with 10 additions and 6 deletions
  1. 2 6
      src/core/tUnification.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue9593.hx

+ 2 - 6
src/core/tUnification.ml

@@ -80,7 +80,6 @@ module Monomorph = struct
 		let types = DynArray.create () in
 		let types = DynArray.create () in
 		let fields = ref PMap.empty in
 		let fields = ref PMap.empty in
 		let is_open = ref false in
 		let is_open = ref false in
-		let is_empty = ref false in
 		let rec check constr = match constr with
 		let rec check constr = match constr with
 			| MMono(m2,name) ->
 			| MMono(m2,name) ->
 				begin match m2.tm_type with
 				begin match m2.tm_type with
@@ -93,18 +92,15 @@ module Monomorph = struct
 				fields := PMap.add cf.cf_name cf !fields;
 				fields := PMap.add cf.cf_name cf !fields;
 			| MType(t2,name) ->
 			| MType(t2,name) ->
 				DynArray.add types (t2,name)
 				DynArray.add types (t2,name)
-			| MOpenStructure ->
-				is_open := true
+			| MOpenStructure
 			| MEmptyStructure ->
 			| MEmptyStructure ->
-				is_empty := true;
+				is_open := true
 		in
 		in
 		List.iter check m.tm_constraints;
 		List.iter check m.tm_constraints;
 		if DynArray.length types > 0 then
 		if DynArray.length types > 0 then
 			CTypes (DynArray.to_list types)
 			CTypes (DynArray.to_list types)
 		else if not (PMap.is_empty !fields) || !is_open then
 		else if not (PMap.is_empty !fields) || !is_open then
 			CStructural(!fields,!is_open)
 			CStructural(!fields,!is_open)
-		else if !is_empty then
-			CStructural(PMap.empty,true)
 		else
 		else
 			CUnknown
 			CUnknown
 
 

+ 8 - 0
tests/unit/src/unit/issues/Issue9593.hx

@@ -7,5 +7,13 @@ class Issue9593 extends Test {
 		utest.Assert.pass();
 		utest.Assert.pass();
 	}
 	}
 
 
+	function test2() {
+		foo(function(res) {
+			res.error;
+			res.file;
+		});
+		utest.Assert.pass();
+	}
+
 	static function foo<T:{}>(cb:T->Void):Void {}
 	static function foo<T:{}>(cb:T->Void):Void {}
 }
 }