Skip to content

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

@tobil4sk

Description

@tobil4sk
// 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: 145e55f.

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.

let rec dump_classes indent classes =
match classes with
| [] -> ()
| [ c ] -> output_cpp (indent ^ "return inClassId==(int)" ^ txt c ^ ";\n")
| [ c; c1 ] ->
output_cpp
(indent ^ "return inClassId==(int)" ^ txt c ^ " || inClassId==(int)" ^ txt c1 ^ ";\n")
| _ ->
let len = List.length classes in
let mid = List.nth classes (len / 2) in
let low, high = List.partition (fun e -> e <= mid) classes in
output_cpp (indent ^ "if (inClassId<=(int)" ^ txt mid ^ ") {\n");
dump_classes (indent ^ "\t") low;
output_cpp (indent ^ "} else {\n");
dump_classes (indent ^ "\t") high;
output_cpp (indent ^ "}\n")
in

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions