فهرست منبع

fixed erasing typedef on field access to forwarded abstract fields
closes #8919

Aleksandr Kuzmenko 5 سال پیش
والد
کامیت
439fb0851f
3فایلهای تغییر یافته به همراه44 افزوده شده و 8 حذف شده
  1. 8 8
      src/core/abstract.ml
  2. 17 0
      tests/unit/src/unit/issues/Issue8919.hx
  3. 19 0
      tests/unit/src/unit/issues/misc/Issue8919Macro.hx

+ 8 - 8
src/core/abstract.ml

@@ -68,17 +68,17 @@ let rec get_underlying_type ?(return_first=false) a pl =
 					let s = String.concat " -> " (List.map (fun t -> s_type pctx t) (List.rev (t :: underlying_type_stack.rec_stack))) in
 					let s = String.concat " -> " (List.map (fun t -> s_type pctx t) (List.rev (t :: underlying_type_stack.rec_stack))) in
 					error ("Abstract chain detected: " ^ s) a.a_pos
 					error ("Abstract chain detected: " ^ s) a.a_pos
 				end;
 				end;
-				(*
-					Even if only the first underlying type was requested
-					keep traversing to detect mutually recursive abstracts
-				*)
-				let result = get_underlying_type a tl in
-				if return_first then t
-				else result
+				get_underlying_type a tl
 			| _ ->
 			| _ ->
 				t
 				t
 		in
 		in
-		rec_stack_loop underlying_type_stack (TAbstract(a,pl)) loop t
+		(*
+			Even if only the first underlying type was requested
+			keep traversing to detect mutually recursive abstracts
+		*)
+		let result = rec_stack_loop underlying_type_stack (TAbstract(a,pl)) loop t in
+		if return_first then t
+		else result
 	in
 	in
 	try
 	try
 		if not (Meta.has Meta.MultiType a.a_meta) then raise Not_found;
 		if not (Meta.has Meta.MultiType a.a_meta) then raise Not_found;

+ 17 - 0
tests/unit/src/unit/issues/Issue8919.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+
+import unit.issues.misc.Issue8919Macro;
+
+private typedef TestTd = {
+	var s:String;
+}
+
+@:forward
+private abstract TestAb(TestTd) from TestTd {}
+
+class Issue8919 extends Test {
+	function test() {
+		var a:TestAb = {s:"Hi!"};
+		Issue8919Macro.check(a.s);
+	}
+}

+ 19 - 0
tests/unit/src/unit/issues/misc/Issue8919Macro.hx

@@ -0,0 +1,19 @@
+package unit.issues.misc;
+
+import haxe.macro.Expr;
+import haxe.macro.Context;
+
+using haxe.macro.Tools;
+
+class Issue8919Macro {
+	macro static public function check(fieldAccess:Expr):Expr {
+		var typed = Context.typeExpr(fieldAccess);
+		return switch typed.expr {
+			case TField({ t:TType(_.get() => t, []) }, fa) if(t.name == 'TestTd'):
+				macro @:pos(fieldAccess.pos) noAssert();
+			case _:
+				var msg = '`${fieldAccess.toString()}` should be typed as `TField({ t:TType(TypeTd) }, _)`';
+				macro @:pos(fieldAccess.pos) assert($v{msg});
+		}
+	}
+}