HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
298 stars 191 forks source link

conflicting return for iterator function #509

Closed ibilon closed 8 years ago

ibilon commented 8 years ago

When trying to compile a haxeui-hxwidgets app with hxcpp I get this error:

In file included from ./src/__boot__.cpp:989:0:
include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h:49:8: error: conflicting return type specified for ‘virtual int haxe::ds::_GenericStack::GenericStackIterator_hscript_Token_obj::hasNext()’
   Bool hasNext();
        ^
In file included from /home/ibilon/Code/Haxelibs/hxcpp/include/Array.h:4:0,
                 from /home/ibilon/Code/Haxelibs/hxcpp/include/hxcpp.h:322:
/home/ibilon/Code/Haxelibs/hxcpp/include/cpp/FastIterator.h:24:17: error:   overriding ‘bool cpp::FastIterator_obj<T>::hasNext() [with T = hx::ObjectPtr<hscript::Token_obj>]’
    virtual bool hasNext() = 0;
                 ^
Error: Build failed

But when I compile the tests of hscript they work and the generated file include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h is the exact same file as the one that fails in the haxeui-widgets app.

Can't figure out why it doesn't compile.

ibilon commented 8 years ago

Changing the line in the file include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h from Bool to bool makes it work.

hughsando commented 8 years ago

I guess something is #defining Bool to be Int - probably in haxeui-widgets. Can you maybe #undef it after including the wxWidgets header?

On Tue, Sep 13, 2016 at 1:09 AM, Valentin Lemière notifications@github.com wrote:

Changing the line in the file include/haxe/ds/_GenericStack/ GenericStackIterator_hscript_Token.h from Bool to bool makes it work.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/509#issuecomment-246417980, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1piRfXW1lHaIRtBru4VammKuoqR1ks5qpYc4gaJpZM4J6zbW .

ibilon commented 8 years ago

Indeed there's something like that typedef int Bool; that's going to be an issue right? Can't undef that.

hughsando commented 8 years ago

no - not a typedef, I was thinking a define hxcpp does: typedef bool Bool;

not sure where there is not a conflict. Maybe theirs is in a namespace, and we should use "::Bool".

I guess I should move things to little 'bool', "int" and use "hx::Float" to avoid conflicts like this.

ibilon commented 8 years ago

The typedef is in wxWidgets, but doesn't look to be in a namespace :/ Would it work to add the hxcpp Bool to a namespace, as a quick fix?

hughsando commented 8 years ago

If changing the "virtual bool hasNext() = 0;" to "virtual Bool hasNext() = 0;" fixes the problem, then I think this is ok, because at least it is consistent (even if it is the wrong "Bool").

On Thu, Sep 15, 2016 at 2:52 PM, Valentin Lemière notifications@github.com wrote:

The typedef is in wxWidgets, but doesn't look to be in a namespace :/ Would it work to add the hxcpp Bool to a namespace, as a quick fix?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/509#issuecomment-247250297, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1lU7DbbRAeVNLjC83xN2p8cbB3WGks5qqOtKgaJpZM4J6zbW .

ibilon commented 8 years ago

It's the other way around, need to make Bool to bool ;)

https://github.com/HaxeFoundation/hxcpp/blob/master/include/cpp/FastIterator.h#L11 FastIterator's hasNext is bool, but generated code for haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h is Bool

hughsando commented 8 years ago

But if the hasNext is expecting to return and int, might that work too?

On Thu, Sep 15, 2016 at 3:15 PM, Valentin Lemière notifications@github.com wrote:

It's the other way around, need to make Bool to bool ;)

https://github.com/HaxeFoundation/hxcpp/blob/master/include/cpp/ FastIterator.h#L11 FastIterator's hasNext is bool, but generated code for haxe/ds/_GenericStack/GenericStackIteratorhscript Token.h is Bool

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/509#issuecomment-247254189, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1givPA09yBFjCYWln6c4IDOEdmivks5qqPCDgaJpZM4J6zbW .

ibilon commented 8 years ago

In that specific case I guess it'd work, though I'll have to check.

ibilon commented 8 years ago

Actually it doesn't work

In file included from ./src/__boot__.cpp:989:0:
include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h:49:8: error: conflicting return type specified for ‘virtual int haxe::ds::_GenericStack::GenericStackIterator_hscript_Token_obj::hasNext()’
   Bool hasNext();
        ^
In file included from /home/ibilon/Code/Haxelibs/hxcpp/include/Array.h:4:0,
                 from /home/ibilon/Code/Haxelibs/hxcpp/include/hxcpp.h:322:
/home/ibilon/Code/Haxelibs/hxcpp/include/cpp/FastIterator.h:24:17: error:   overriding ‘Bool cpp::FastIterator_obj<T>::hasNext() [with T = hx::ObjectPtr<hscript::Token_obj>; Bool = bool]’
    virtual Bool hasNext() = 0;
                 ^
Error: Build failed

not sure why though, maybe the effect of wxWidgets is limited to some files?

hughsando commented 8 years ago

I'm really expecting an error. If I do this:

typedef bool Bool;
typedef int Bool;

I get a compile error. So one of these must not be able to "see" the other definition. Perhaps because something is in a namespace or class definition. The hxcpp one should be global - not sure where the wxWidgets one is. Is the wxWidgets code imported into the global namespace?

ibilon commented 8 years ago

I think it's in the global namespace https://github.com/wxWidgets/wxWidgets/blob/v3.0.2/include/wx/x11/nanox/X11/Xlib.h#L20 Then used with @:headerCode("#include <>") or @:include("") on haxe extern classes.

Looking at the error for include/cpp/FastIterator.h it says [with T = hx::ObjectPtr<hscript::Token_obj>; Bool = bool] it does think that Bool is bool.

I'm really expecting an error. If I do this:

typedef bool Bool; typedef int Bool;

I get a compile error.

Tried it to be sure and I also have a compile error.

Changing the hxcpp typedefs (found two) to int makes it work, but strange that it doesn't complain before.

Isn't simpler to use bool everywhere in hxcpp? Since it's a typedef anyway.

ibilon commented 8 years ago

Tried to replace Bool by bool, somehow hacked it https://github.com/ibilon/haxe/commit/ef825d462f17d1bafa4d194ef8b2882ea02293ca https://github.com/ibilon/hxcpp/commit/30235968675447036415cc31c1fb632c93fd9bcb but since I have no idea what I'm doing code like Std.is(i, Bool) failed at compile time :)

Also makes my code compile, but not sure if that's a good change or not.

hughsando commented 8 years ago

It should be possible to generate "bool" everywhere instead of "Bool". I would then need to change the api level to 331 and conditionally remove this typedef for the newer compiler. Then it would not matter about this conflict - only when you use the newer compiler.

Is it possible to isolate the files that need to include the XLib.h file from the ones that need to #include hxcpp? Or is this basically "all of wxWidgets" ?

Another hack might be to change the XLib.h file to typedef Bool as bool too.

On Sun, Sep 18, 2016 at 10:53 PM, Valentin Lemière <notifications@github.com

wrote:

Tried to replace Bool by bool, somehow hacked it ibilon/haxe@ef825d4 https://github.com/ibilon/haxe/commit/ef825d462f17d1bafa4d194ef8b2882ea02293ca ibilon@3023596 https://github.com/ibilon/hxcpp/commit/30235968675447036415cc31c1fb632c93fd9bcb but since I have no idea what I'm doing code like Std.is(i, Bool) failed at compile time :)

Also makes my code compile, but not sure if that's a good change or not.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/509#issuecomment-247852211, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1kE9n81TBhWxII66M7hW1G5xJwoVks5qrVB3gaJpZM4J6zbW .

ibilon commented 8 years ago

Is it possible to isolate the files that need to include the XLib.h file from the ones that need to #include hxcpp? Or is this basically "all of wxWidgets" ?

Looks like it gets pull from about anywhere in wxWidgets :/

Another hack might be to change the XLib.h file to typedef Bool as bool too.

wxWidgets is used as a system library, and I don't know the effect of this change on the compatibility with the precompiled .so files. So unless there's really no other choice I'd like to avoid this if possible.

ibilon commented 8 years ago

In the log I see groups Compiling group 'hxcpp_std', how easy would it be to have groups per haxe package? That way I just add the wx headers for the hx.widgets and wx.widgets groups and the user code + the part about hscript is left untouched and no issue.

hughsando commented 8 years ago

I think the issue might be coming from the "boot" class - which will have both the hscript and wx includes in it, so hard to avoid.

So, I have removed these typedefs if you are using the latest version of hxcpp and haxe, https://github.com/HaxeFoundation/haxe/commit/b638b8285cf3335432848e9d7f7e6dadec2ff614

ibilon commented 8 years ago

Updated hxcpp and haxe to latest but I still get:

In file included from ./src/__boot__.cpp:1040:0:
include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.h:51:8: error: conflicting return type specified for ‘virtual int haxe::ds::_GenericStack::GenericStackIterator_hscript_Token_obj::hasNext()’
   Bool hasNext();
        ^
In file included from /home/ibilon/Code/Haxe/libs/hxcpp/include/Array.h:4:0,
                 from /home/ibilon/Code/Haxe/libs/hxcpp/include/hxcpp.h:326:
/home/ibilon/Code/Haxe/libs/hxcpp/include/cpp/FastIterator.h:24:17: error:   overriding ‘bool cpp::FastIterator_obj<T>::hasNext() [with T = hx::ObjectPtr<hscript::Token_obj>]’
    virtual bool hasNext() = 0;
                 ^
Error: Build failed

In include/haxe/ds/_GenericStack/GenericStackIterator_hscript_Token.hit stills generate Bool hasNext();

hughsando commented 8 years ago

Looks like you are not using the new haxe somehow. The generated code should have the api level set to '331' and at this level, hxcpp should not be defining 'Bool' at all, so I would expect a lot more errors.

ibilon commented 8 years ago

Sorry, my fault, forgot the make install step,

it works now, thanks.