hxcpp
hxcpp copied to clipboard
Compilation error with constructible generics
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
import haxe.Constraints.Constructible;
class Foo {
public function new() {
}
@:generic
public function create<T:Constructible<Void->Void>>(cls:Class<T>):Bar<T> {
var bar = new Bar<T>();
bar.something = new T();
return bar;
}
}
@:generic
class Bar<T:Constructible<Void->Void>> {
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
so some more info here, if i add this to the "Foo" haxe class:
@:headerInclude("Bar.h")
class Foo {
...
}
Then things compile
EDIT: thats not completely accurate, i had some files left over it seems - it looks like its not generating a Bar.h file at all, just the generic versions
possibly the same issue as this: https://github.com/HaxeFoundation/haxe/issues/5482