haxe icon indicating copy to clipboard operation
haxe copied to clipboard

[cpp] Infinite loop in compiler when inheriting from cpp.Pointer

Open tobil4sk opened this issue 3 months ago • 2 comments

// MyPointer.hx
class MyPointer extends cpp.Pointer<Int> {}
# build.hxml
MyPointer
--cpp out

This has always generated broken code, however, it has only started triggering an infinite loop since: 145e55f0c007498513ef4024fb2f963fb95501f6.

Prior to that change, it seems ids didn't get added for extern classes, however, now they are added. Since cpp.ConstPointer and cpp.Pointer both point to the same native type, the same id is added twice, which breaks an assumption made by this dump_classes function and causes the code to loop forever.

https://github.com/HaxeFoundation/haxe/blob/aa3ecc55029f14444960b4b1b0818a0fdb6082d9/src/generators/cpp/gen/cppGenClassImplementation.ml#L372-L388

@Aidan63 Do you think we should exclude @:nativeGen and extern classes from the id generation?

tobil4sk avatar Sep 23 '25 18:09 tobil4sk

I think that makes sense, the ids are used for type checking so don't server a purpose for non haxe generated classes.

Aidan63 avatar Sep 24 '25 13:09 Aidan63

Hm, I've managed to reproduce the infinite loop without externs involved. This version is also broken with 4.3.7:

class Parent {}

@:native("Parent")
class Child extends Parent {}

I'm not sure if it's possible to construct a case where you have an observable difference in runtime behaviour depending on whether extern/nativeGen classes receive ids, so I'm not too sure how to come up with a test for that.

tobil4sk avatar Sep 25 '25 08:09 tobil4sk