Browse Source

error on recursive anons (fixes #7997, closes #8604)

Aleksandr Kuzmenko 6 years ago
parent
commit
e32f221174

+ 15 - 0
src/core/type.ml

@@ -1724,6 +1724,19 @@ let rec link e a b =
 		true
 	end
 
+let would_produce_recursive_anon field_accpetor field_donor =
+	try
+		(match !(field_accpetor.a_status) with
+		| Opened ->
+			PMap.iter (fun n field ->
+				match follow field.cf_type with
+				| TAnon a when field_accpetor == a -> raise Exit
+				| _ -> ()
+			) field_donor.a_fields;
+		| _ -> ());
+		false
+	with Exit -> true
+
 let link_dynamic a b = match follow a,follow b with
 	| TMono r,TDynamic _ -> r := Some b
 	| TDynamic _,TMono r -> r := Some a
@@ -1964,6 +1977,7 @@ let rec type_eq param a b =
 			| AbstractStatics a -> (match !(a1.a_status) with AbstractStatics a2 when a == a2 -> () | _ -> error [])
 			| _ -> ()
 			);
+			if would_produce_recursive_anon a1 a2 || would_produce_recursive_anon a2 a1 then error [cannot_unify a b];
 			PMap.iter (fun n f1 ->
 				try
 					let f2 = PMap.find n a2.a_fields in
@@ -2302,6 +2316,7 @@ and unify_abstracts a b a1 tl1 a2 tl2 =
 			error [cannot_unify a b]
 
 and unify_anons a b a1 a2 =
+	if would_produce_recursive_anon a1 a2 then error [cannot_unify a b];
 	(try
 		PMap.iter (fun n f2 ->
 		try

+ 8 - 0
tests/misc/projects/Issue7997/Main.hx

@@ -0,0 +1,8 @@
+class Main {
+	static function main() {
+		function loop(type) {
+			type.args.field;
+			loop(type.args);
+		}
+	}
+}

+ 1 - 0
tests/misc/projects/Issue7997/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 2 - 0
tests/misc/projects/Issue7997/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:5: characters 9-18 : {+ field : Unknown<0> } should be {+ args : {+ field : Unknown<0> } }
+Main.hx:5: characters 9-18 : For function argument 'type'