فهرست منبع

Error on mutually recursive abstracts (#8608)

* error on mutually recursive abstracts

* test

* fix test #4891
Aleksandr Kuzmenko 6 سال پیش
والد
کامیت
aaaa79bc31

+ 9 - 3
src/typing/typeloadModule.ml

@@ -771,10 +771,16 @@ let init_module_type ctx context_init do_init (decl,p) =
 				if Meta.has Meta.CoreType a.a_meta then error "@:coreType abstracts cannot have an underlying type" p;
 				let at = load_complex_type ctx true t in
 				delay ctx PForce (fun () ->
-					begin match follow at with
-						| TAbstract(a2,_) when a == a2 -> error "Abstract underlying type cannot be recursive" a.a_pos
+					let rec loop stack t =
+						match follow t with
+						| TAbstract(a,_) when not (Meta.has Meta.CoreType a.a_meta) ->
+							if List.memq a stack then
+								error "Abstract underlying type cannot be recursive" a.a_pos
+							else
+								loop (a :: stack) a.a_this
 						| _ -> ()
-					end;
+					in
+					loop [] at
 				);
 				a.a_this <- at;
 				is_type := true;

+ 2 - 1
tests/misc/projects/Issue4891/compile-fail.hxml.stderr

@@ -1 +1,2 @@
-Main.hx:6: characters 9-24 : { } should be Ab1
+Main.hx:6: characters 9-24 : { } should be Ab1
+Main.hx:1: characters 1-30 : Abstract underlying type cannot be recursive

+ 11 - 0
tests/misc/projects/Issue8608/Main.hx

@@ -0,0 +1,11 @@
+class Main {
+	static function main() {}
+}
+
+abstract Test(Test2) {
+	public inline function new() {
+		this = null;
+	}
+}
+
+abstract Test2(Test) {}

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

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

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

@@ -0,0 +1 @@
+Main.hx:5: lines 5-9 : Abstract underlying type cannot be recursive