Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Crash when declaring a nested struct with a variable of the same type #3025

Closed
guna-sd opened this issue Jun 12, 2024 · 3 comments
Closed
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@guna-sd
Copy link

guna-sd commented Jun 12, 2024

Bug description

When declaring a struct that contains a variable of its own type, the code crashes. This issue is not limited to any specific struct but occurs with any struct that includes a variable of the same struct type. The expected behavior is for the code to compile without errors, but it results in a crash instead.

This issue appears to be related to the recursive nature of the struct declaration, where a struct contains a variable of its own type. This problem is critical as it affects the ability to define common data structures like linked lists, trees, and others that require self-referential types.

Steps to reproduce

issue code

@value
struct Node:
    var data: Int
    var next: Optional[Node]

Crash log

[34229:34229:20240612,222743.659602:WARNING process_reader_linux.cc:144] no stack mapping
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: /home/guna/.modular/pkg/packages.modular.com_mojo/bin/mojo /home/guna/Projects/new/test.mojo
[34229:34230:20240612,222743.692664:ERROR directory_reader_posix.cc:42] opendir /home/guna/.modular/crashdb/attachments/542b6caf-68ed-4ad1-9bf0-6a0f03aa4c0d: No such file or directory (2)
#0 0x000059c6b1289438 (/home/guna/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x12a1438)
#1 0x000059c6b128725e (/home/guna/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x129f25e)
#2 0x000059c6b1289acd (/home/guna/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x12a1acd)
...
#255 0x000059c6b17c1950 (/home/guna/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x17d9950)
mojo crashed!
Please file a bug report.
Segmentation fault (core dumped)

System information

Ubuntu 24.04 LTS
mojo 24.4.0 (2cb57382)
modular 0.8.0 (39a426b5)
@guna-sd guna-sd added bug Something isn't working mojo-repo Tag all issues with this label labels Jun 12, 2024
Copy link
Collaborator

Looks similar to #2208.

Copy link
Collaborator

Should this also error out? In the latest nightly build (mojo 2024.6.1405 (ceceb171), it compiles. @jeff @tatiana

@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2024
@suahelen
Copy link

Should this also error out? In the latest nightly build (mojo 2024.6.1405 (ceceb171), it compiles. @jeff @tatiana

The struct definition seems to compile but as soon as I try to instantiate it in main the error is there again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants