HaxeFoundation / HaxeFoundation/hxcpp

Compilation error with constructible generics

Open
#958 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

Is there a reason why this doesnt work on hxcpp, but seems to work on every other haxe target ive tested:

https://try.haxe.org/#0be4c0B4

```haxe
import haxe.Constraints.Constructible;

class Foo {
public function new() {
}

@:generic
public function createVoid>>(cls:Class):Bar {
var bar = new Bar();
bar.something = new T();
return bar;
}
}

@:generic
class BarVoid>> {
public var something:T;

public function new() {
}

public function newSomething():T {
return new T();
}
}

class Something {
public function new() {
}
}

class SomethingElse {
public function new() {
}
}

class Test {
static function main() {
var f = new Foo();
f.create(Something);
f.create(SomethingElse);
}
}
```

the error is:

```
Error: Main.cpp
include\Foo.h(41): error C2039: 'Bar': is not a member of '`global namespace''
include\Foo.h(41): error C3646: 'create_Something': unknown override specifier
include\Foo.h(41): error C2059: syntax error: '('
include\Foo.h(41): error C2238: unexpected token(s) preceding ';'
./src/Main.cpp(36): error C2039: 'create_Something': is not a member of 'Foo_obj'
include\Foo.h(13): note: see declaration of 'Foo_obj'

Error: __boot__.cpp
include\Foo.h(41): error C2039: 'Bar': is not a member of '`global namespace''
include\Foo.h(41): error C3646: 'create_Something': unknown override specifier
include\Foo.h(41): error C2059: syntax error: '('
include\Foo.h(41): error C2238: unexpected token(s) preceding ';'

Error: Foo.cpp
include\Foo.h(41): error C2039: 'Bar': is not a member of '`global namespace''
include\Foo.h(41): error C3646: 'create_Something': unknown override specifier
include\Foo.h(41): error C2059: syntax error: '('
include\Foo.h(41): error C2238: unexpected token(s) preceding ';'
./src/Foo.cpp(36): error C2039: 'Bar': is not a member of '`global namespace''
./src/Foo.cpp(36): error C2039: 'create_Something': is not a member of 'Foo_obj'
include\Foo.h(13): note: see declaration of 'Foo_obj'
./src/Foo.cpp(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
./src/Foo.cpp(36): error C2146: syntax error: missing ';' before identifier 'create_Something'
./src/Foo.cpp(36): error C2143: syntax error: missing ';' before '{'
./src/Foo.cpp(36): error C2447: '{': missing function header (old-style formal list?)
./src/Foo.cpp(44): error C2039: 'create_Something': is not a member of 'Foo_obj'
include\Foo.h(13): note: see declaration of 'Foo_obj'

Error: Build failed
Build halted with errors (haxe.exe).
```

It seem to have an issue with the `::Bar create_Something(::hx::Class cls);` saying it cant find it, however, there is a `Bar.h` and that does contain a `HX_DECLARE_CLASS0(Bar)` - im unsure what that cpp macro does, but i would _presume_ its declaring a class?

Any thoughts / help? Is this a bug or am i misusing something? I would have thought other haxe targets would have failed if this is a "you cant do that"

Cheers,
Ian

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.