Skip to content

Commit

Permalink
[typer] don't hide abstract type when resolving through @:forward
Browse files Browse the repository at this point in the history
closes #11526
  • Loading branch information
Simn committed Jan 30, 2024
1 parent b0ec862 commit 9e7a820
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/typing/fields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tests/optimization/src/TestInlineConstructors.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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];
}
}

5 comments on commit 9e7a820

@kLabz
Copy link
Contributor

@kLabz kLabz commented on 9e7a820 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leads to issues with the late C# target, where

		var arr = new cs.NativeArray<SomeStruct>(10);
		cs.Lib.fixed({
			var arrptr = cs.Lib.pointerOfArray(arr);
			for (i in 0...10)
			{
				(arrptr + i).acc.int = i;
				(arrptr + i).acc.float = i + i / 10;
			}

is turned into (simplified):

global::unit._TestCSharp.SomeStruct[] arr = new global::unit._TestCSharp.SomeStruct[10];
fixed(global::unit._TestCSharp.SomeStruct* __temp_fixed1 = arr) {
  global::unit._TestCSharp.SomeStruct* arrptr = __temp_fixed1;
  (((global::unit._TestCSharp.SomeStruct*) (( arrptr + 0 )) )).@int = 0;
}

Which raises

error CS0023: The `.' operator cannot be applied to operand of type `unit._TestCSharp.SomeStruct*'

Any idea what's wrong here / if it could also have impact on other targets?

@Simn
Copy link
Member Author

@Simn Simn commented on 9e7a820 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't this have some followup commits that dealt with the C# problems? I only remember being annoyed by it...

@kLabz
Copy link
Contributor

@kLabz kLabz commented on 9e7a820 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's a possibility, will dig a bit!

@RblSb
Copy link
Member

@RblSb RblSb commented on 9e7a820 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#11527 ?

@kLabz
Copy link
Contributor

@kLabz kLabz commented on 9e7a820 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I included that

Please sign in to comment.