HaxeFoundation / HaxeFoundation/hxcpp

compilation error with nativeGen on interface

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

Description

**Environment**
macos monterey 12.1
haxe 4.2.4
hxcpp 4.2.1

The error can be reproduced by compiling the following two modules for the cpp target.

```
//LogManager.hx
package log;

@:nativeGen
interface Logger {
function info(line: String): Void;
}

class LogManager {
public static function getLogger(): Logger {
return null;
}
}
```

```
//Client.hx
package log;

class Client {
static var logger = LogManager.getLogger();
}
```

The error reported is

> Error: In file included from ./src/log/Client.cpp:1:
> In file included from /usr/local/Cellar/haxe/4.2.4/lib/haxe/lib/hxcpp/4,2,1/include/hxcpp.h:353:
> /usr/local/Cellar/haxe/4.2.4/lib/haxe/lib/hxcpp/4,2,1/include/Dynamic.h:107:34: error: ambiguous conversion for functional-style cast from 'const Dynamic' to 'hx::Native'
> RETURN_ Cast() const { return RETURN_(*this); }
> ^~~~~~~~~~~~~
> ./src/log/Client.cpp:53:55: note: in instantiation of function template specialization 'Dynamic::Cast>' requested here
> if (HX_FIELD_EQ(inName,"logger") ) { logger=ioValue.Cast< ::hx::Native< log::Logger* > >(); return true; }
> ^
> /usr/local/Cellar/haxe/4.2.4/lib/haxe/lib/hxcpp/4,2,1/include/hx/Native.h:61:10: note: candidate constructor
> Native (const Native &inNative) : ptr(inNative.ptr) { }
> ^
> /usr/local/Cellar/haxe/4.2.4/lib/haxe/lib/hxcpp/4,2,1/include/hx/Native.h:63:10: note: candidate constructor
> Native (const cpp::Variant &inVariant) {
> ^
> 1 error generated.

If the metadata @:nativeGen is removed from the interface Logger, the compilation works fine. But I need it because the interface is part of a library for which the end-users will provide a concrete implementation.

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.