Recursive C structures blow the stack when compiling #760
Labels
accepting contributions
Issues that are suitable to be worked on by anybody, not just maintainers
bug
Defects, unintended behaviour, etc
compiler
Changes related to the compiler
Please describe the bug
The compiler doesn't handle recursive C structures gracefully, i.e. the following code crashes it:
The problem here is that when we try to calculate the struct size for LLVM, we encounter an infinite loop and blow the stack. This problem would also be something one could encounter using user-defined value types (per #750), when/if we support those.
To handle this, we need a way to detect if a
class extern
class is recursive and if so produce a compile-time error. At least forclass extern
this isn't too difficult and comes down to the following:class extern
that contains the surrounding classFor custom value types it's more tricky as they can be generic. This means we don't know if a type is recursive until its specialized. At that point, producing a meaningful error may prove difficult.
We could instead check at the initialization site, but then we pay an extra compile-time cost for every initialization of a value type, which I'd like to avoid.
Operating system
Fedora
Inko version
main
The text was updated successfully, but these errors were encountered: