HaxeFoundation / HaxeFoundation/haxe

Const propagation for inlined dynamic argument ignores haxe.extern.AsVar

Open
#12,546 3 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() {
var x:haxe.extern.AsVar = 10;
#if php
php.Syntax.code("{0} = 0", x);
#elseif js
js.Syntax.code("{0} = 0", x);
#end
Sys.print(x);
}
```
This issue happens across targets:
```
haxe --main Main --php testphp -D analyzer-optimize
haxe --main Main --js out.js -lib hxnodejs -D analyzer-optimize
```

PHP output:
```php
$b = 10;
$b = 0;
echo("10");
```

JS output:
```js
var b = 10;
b = 0;
process.stdout.write("10");
```

This does not happen if you use trace or another function instead of print or println.

The real life scenario where I ran into this was: https://github.com/HaxeFoundation/haxe/pull/12520#issuecomment-3821542487.

Contributor guide

Open the contributing guide

Research direction

Start by running the two Haxe commands in the issue with analyzer optimization enabled, using the sample involving haxe.extern.AsVar, php.Syntax.code or js.Syntax.code, and Sys.print. Compare the generated PHP and JavaScript with the shown output; done means the assignment through the dynamic argument is reflected when Sys.print emits the value, rather than the original constant.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.