HaxeFoundation / HaxeFoundation/haxe

Inconsistent behavior with abstract array inline functions

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

Description

After trying to figure out why HaxeFlixel's [MatrixVector.set](https://github.com/HaxeFlixel/flixel/blob/83aec8e8c8938318e6c12f2a1456f573c9b8943a/flixel/graphics/frames/FlxFrame.hx#L845) function did not behave correctly when targeting Hashlink, I found out inlined functions caused the compiler to not create unique references for variables used from the abstract. I've created a code sample where this is viewable: https://try.haxe.org/#3852320A. Instead of the sample performing `this[0] = y; this[1] = x;` it would behave as `this[0] = this[1]; this[1] = this[0];`. The traced value should return as `[0, 10]` but instead returns as `[0, 0]`, you can see this work correctly when switching the target to Javascript or Eval.

I originally wrote this off as an odd issue with Hashlink and was planning to write an issue on their repo until I messed around with the test more and found out that this behavior is also reproducible on non-hashlink targets when the inline function's default parameter values are omitted, leading me to believe that this might stem from Haxe instead.

Sample with omitted default parameter values: https://try.haxe.org/#b7e8Eb21. No targets return [0, 10].

The compiler can be forced to create an unique reference when the variable is used inside of the inlined function, for example adding a trace in the function like `trace(x, y);` would fix it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.