HaxeFoundation / HaxeFoundation/haxe

extern inline new causes `this` used as variable name in cpp code

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

Description

This code generates invalid cpp code
```haxe
class Foo {

var map: Map;
var keys: Iterator;

extern inline public function new(bar: Bar ) {
this.map = bar.map;
this.keys = map.keys();
}

inline public function foo(): Void {
while (keys.hasNext()) {
trace(keys.next());
}
}
}

class Bar {
public var map: Map = new Map();
public function new() {
}
}
class Main {

static function main() {

var bar: Bar = new Bar();
bar.map[100] = 200;
var foo: Foo = new Foo(bar);
foo.foo();
}
}
```
Cpp compilation fails with errors
```
./src/Foo.cpp(27): error C2059: syntax error: ';'
./src/Foo.cpp(27): error C2059: syntax error: 'this'
./src/Foo.cpp(31): error C2059: syntax error: '}'
./src/Foo.cpp(31): error C2143: syntax error: missing ';' before '}'
./src/Foo.cpp(33): error C2143: syntax error: missing ';' before '{'
./src/Foo.cpp(33): error C2447: '{': missing function header (old-style formal list?)
```
Generated code looks like this
```cpp
23 void Foo_obj::__construct( ::Bar bar){
24 HX_STACKFRAME(&_hx_pos_33f1e4dc58dc3aff_6_new)
25 HXLINE( 7) this->map = bar->map;
26 HXLINE( 8) this->keys = {
27 HXLINE( 8) ::Dynamic this = this->map;
28 HXDLIN( 8) ::haxe::IMap_obj::keys(this);
29 }
30 ;
31 }
```

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.