Browse Source

[typer] add MEmptyStructure to make it more explicit

closes #9393
Simon Krajewski 5 years ago
parent
commit
49c5095714
4 changed files with 19 additions and 1 deletions
  1. 1 0
      src/core/tPrinting.ml
  2. 1 0
      src/core/tType.ml
  3. 6 1
      src/core/tUnification.ml
  4. 11 0
      tests/unit/src/unit/issues/Issue9593.hx

+ 1 - 0
src/core/tPrinting.ml

@@ -111,6 +111,7 @@ and s_constraint = function
 	| MField cf -> Printf.sprintf "MField %s" cf.cf_name
 	| MType(t,_) -> Printf.sprintf "MType %s" (s_type_kind t)
 	| MOpenStructure -> "MOpenStructure"
+	| MEmptyStructure -> "MEmptyStructure"
 
 let s_access is_read = function
 	| AccNormal -> "default"

+ 1 - 0
src/core/tType.ml

@@ -53,6 +53,7 @@ and tmono_constraint =
 	| MField of tclass_field
 	| MType of t * string option
 	| MOpenStructure
+	| MEmptyStructure
 
 and tmono_constraint_kind =
 	| CUnknown

+ 6 - 1
src/core/tUnification.ml

@@ -69,7 +69,7 @@ module Monomorph = struct
 				(MField cf) :: l
 			) an.a_fields []
 		| TAnon _ ->
-			[MOpenStructure]
+			[MEmptyStructure]
 		| _ ->
 			[MType(t,name)]
 
@@ -80,6 +80,7 @@ module Monomorph = struct
 		let types = DynArray.create () in
 		let fields = ref PMap.empty in
 		let is_open = ref false in
+		let is_empty = ref false in
 		let rec check constr = match constr with
 			| MMono(m2,name) ->
 				begin match m2.tm_type with
@@ -94,12 +95,16 @@ module Monomorph = struct
 				DynArray.add types (t2,name)
 			| MOpenStructure ->
 				is_open := true
+			| MEmptyStructure ->
+				is_empty := true;
 		in
 		List.iter check m.tm_constraints;
 		if DynArray.length types > 0 then
 			CTypes (DynArray.to_list types)
 		else if not (PMap.is_empty !fields) || !is_open then
 			CStructural(!fields,!is_open)
+		else if !is_empty then
+			CStructural(PMap.empty,true)
 		else
 			CUnknown
 

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

@@ -0,0 +1,11 @@
+package unit.issues;
+import unit.Test;
+
+class Issue9593 extends Test {
+	function test() {
+		foo(function(res) res.error);
+		utest.Assert.pass();
+	}
+
+	static function foo<T:{}>(cb:T->Void):Void {}
+}