From 9e7a820a587fb08d3ad385d4a329f80e3977c81e Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 30 Jan 2024 22:38:45 +0100 Subject: [PATCH] [typer] don't hide abstract type when resolving through @:forward closes #11526 --- src/typing/fields.ml | 2 +- .../src/TestInlineConstructors.hx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/typing/fields.ml b/src/typing/fields.ml index 212430d037b..ffd3a75aae8 100644 --- a/src/typing/fields.ml +++ b/src/typing/fields.ml @@ -270,7 +270,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) = | None -> raise Not_found in 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 let type_field_by_e f e = f e (follow_without_type e.etype) diff --git a/tests/optimization/src/TestInlineConstructors.hx b/tests/optimization/src/TestInlineConstructors.hx index 9bd64113c59..5f67a63c083 100644 --- a/tests/optimization/src/TestInlineConstructors.hx +++ b/tests/optimization/src/TestInlineConstructors.hx @@ -44,6 +44,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 { @:js('return [1,2,3,3];') static function testArrayInlining() { @@ -147,4 +160,10 @@ class TestInlineConstructors extends TestBase { try { a; } catch(_) { a; }; return a.a; } + + @:js('return [5];') + static function testForwardAbstract() { + var p2 = {v: new PA(5)}; + return [p2.v.x]; + } }