HaxeFoundation / HaxeFoundation/haxe
[cpp] Odd interface and inheritance combination generates broken code
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
We ran across this on the coroutine branch a while ago, almost forgot about it.
```haxe
class Base {}
class SubClass extends Base {
public function new() {}
}
interface IBar {
function get():Base;
}
class Foo {
public function get():SubClass {
return new SubClass();
}
}
class Bar extends Foo implements IBar {
public function new() {}
}
function main() {
final b = new Bar();
final o = b.get();
trace(o);
}
```
Which results in cpp errors
```
Error: Bar.cpp
D:/programming/haxe/hxcpp/include\hx/Object.h(310): error C2664: 'void hx::ObjectPtr::CastPtr(hx::Object *,bool)': cannot convert argument 1 from 'OBJ_ *const ' to 'hx::Object *'
with
[
OBJ_=SubClass_obj
]
D:/programming/haxe/hxcpp/include\hx/Object.h(310): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or parenthesized function-style cast
D:/programming/haxe/hxcpp/include\hx/Object.h(282): note: see declaration of 'hx::ObjectPtr::CastPtr'
D:/programming/haxe/hxcpp/include\hx/Object.h(310): note: while trying to match the argument list '(OBJ_ *const , bool)'
with
[
OBJ_=SubClass_obj
]
D:/programming/haxe/hxcpp/include\hx/Object.h(310): note: the template instantiation context (the oldest one first) is
./src/Bar.cpp(44): note: see reference to function template instantiation 'hx::ObjectPtr::ObjectPtr(const hx::ObjectPtr &)' being compiled
./src/Bar.cpp(44): note: see the first reference to 'hx::ObjectPtr::ObjectPtr' in 'Bar_obj::get_da384999'
```
This occurs on 4.3.x releases as well as nightlies so is not a regression from all the gencpp changes.
Contributor guide
Assessment
This issue has not been assessed yet.