Browse Source

[typer] don't hide abstract type when resolving through @:forward

closes #11526
Simon Krajewski 1 year ago
parent
commit
b00bca0e76
2 changed files with 20 additions and 1 deletions
  1. 1 1
      src/typing/fields.ml
  2. 19 0
      tests/optimization/src/TestInlineConstructors.hx

+ 1 - 1
src/typing/fields.ml

@@ -272,7 +272,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 		| None -> raise Not_found
 		| None -> raise Not_found
 	in
 	in
 	let type_field_by_et f e t =
 	let type_field_by_et f e t =
-		f { e with etype = t } (follow_without_type t)
+		f (mk (TCast(e,None)) t e.epos) (follow_without_type t)
 	in
 	in
 	let type_field_by_e f e =
 	let type_field_by_e f e =
 		f e (follow_without_type e.etype)
 		f e (follow_without_type e.etype)

+ 19 - 0
tests/optimization/src/TestInlineConstructors.hx

@@ -38,6 +38,19 @@ class NestedInlineClass {
 	}
 	}
 }
 }
 
 
+class P {
+	public var x:Float;
+
+	public inline function new(x = 0)
+		this.x = x;
+}
+
+@:forward
+abstract PA(P) to P {
+	public inline function new(x)
+		this = new P(x);
+}
+
 class TestInlineConstructors extends TestBase {
 class TestInlineConstructors extends TestBase {
 	@:js('return [1,2,3,3];')
 	@:js('return [1,2,3,3];')
 	static function testArrayInlining() {
 	static function testArrayInlining() {
@@ -130,4 +143,10 @@ class TestInlineConstructors extends TestBase {
 		}
 		}
 		return acc;
 		return acc;
 	}
 	}
+
+	@:js('return [5];')
+	static function testForwardAbstract() {
+		var p2 = {v: new PA(5)};
+		return [p2.v.x];
+	}
 }
 }