Explorar o código

use parameterized abstract to detect chain (closes #4591)

I'm hoping that this doesn't cause any trouble with `fast_eq`.
Simon Krajewski %!s(int64=9) %!d(string=hai) anos
pai
achega
233e8e899f
Modificáronse 2 ficheiros con 13 adicións e 3 borrados
  1. 9 0
      tests/unit/src/unit/issues/Issue4591.hx
  2. 4 3
      type.ml

+ 9 - 0
tests/unit/src/unit/issues/Issue4591.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue4591 extends Test {
+	public function test() {
+		var x:C<C<String>> = null;
+	}
+}
+
+abstract C<T>(T) from T to T { }

+ 4 - 3
type.ml

@@ -1880,11 +1880,12 @@ module Abstract = struct
 
 
 	let rec get_underlying_type a pl =
 	let rec get_underlying_type a pl =
 		let maybe_recurse t =
 		let maybe_recurse t =
-			underlying_type_stack := a :: !underlying_type_stack;
+			underlying_type_stack := (TAbstract(a,pl)) :: !underlying_type_stack;
 			let t = match follow t with
 			let t = match follow t with
 				| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					if List.mem a !underlying_type_stack then begin
-						let s = String.concat " -> " (List.map (fun a -> s_type_path a.a_path) (List.rev (a :: !underlying_type_stack))) in
+					if List.exists (fast_eq t) !underlying_type_stack then begin
+						let pctx = print_context() in
+						let s = String.concat " -> " (List.map (fun t -> s_type pctx t) (List.rev (t :: !underlying_type_stack))) in
 						raise (Error("Abstract chain detected: " ^ s,a.a_pos))
 						raise (Error("Abstract chain detected: " ^ s,a.a_pos))
 					end;
 					end;
 					get_underlying_type a tl
 					get_underlying_type a tl