HaxeFoundation / HaxeFoundation/haxe

Named inline functions get a single implementation for different classes if assigned to an object

Open
#11,283 0 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

If you define externs for two classes, and add an inline static function with the same name in several of those externs, when you pass them as argument to an object they get the same reference to the same generated function, rather than getting two separate functions.

```haxe
extern class NeoTree {
inline static final libName = 'neo-tree';
@:luaDotMethod function setup(opts:{close_if_last_window:Bool}):Void;
inline static function configure():Void {
trace('Stuff NeoTree');
}
}

extern class Comment {
inline static final libName = 'Comment';
@:luaDotMethod function setup():Void;
inline static function configure():Void {
untyped __js__("console.log('hey')");
}
}

class Test {
static function main() {
var x = {
a: Comment.configure,
b: NeoTree.configure
}
trace(x);
}
}
```

If you run that snippet (https://try.haxe.org/#AA3D4015) you will see this output:

```js
// Generated by Haxe 4.3.1
(function ($global) { "use strict";
class _$Test_Test_$Impl_$ {
static configure() {
console.log('hey');
}
}
class Test {
static main() {
console.log("Test.hx:23:",{ a : _$Test_Test_$Impl_$.configure, b : _$Test_Test_$Impl_$.configure});
}
}
class haxe_iterators_ArrayIterator {
constructor(array) {
this.current = 0;
this.array = array;
}
hasNext() {
return this.current < this.array.length;
}
next() {
return this.array[this.current++];
}
}
{
}
Test.main();
})({});
```

As you can see the implementation of the first configure function is missing.
This happens both for Lua and Javascript targets

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.