HaxeFoundation / HaxeFoundation/haxe

inline constructor fails when some function returns `this`

Open
#10,741 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```haxe
function main() {
new Foo(10).foo(new Foo(Math.random()));
}

class Foo {
public var x:Float;

public inline function new(x) this.x = x;

public inline function foo(f:Foo) if (f.x > x) empty();

public inline function empty() {
x *= 0;
return this; // Commenting this line makes inline constructor work.
}
}
```
Results in:
```js
let _this = new Foo(10);
if(Math.random() > _this.x) {
_this.x *= 0;
}
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the Haxe snippet from main() and comparing the generated JavaScript with the inline constructor, foo(), and empty() definitions. Inspect how the returned this from empty() affects inlining. Done means the reproducer generates correct behavior without requiring the return this line to be removed, with a regression test covering it.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.