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] Compiler crash when defining a list of structs based on a common trait. #3944

Open
johnsoez4 opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@johnsoez4
Copy link

Bug description

The Mojo compiler crashes on the line, _list = List[Bar[TFoo]]() in the code example below.
Discussed on Discord with @owenhilyard.
https://discord.com/channels/1087530497313357884/1151418092052815884/1328223895408476275

Steps to reproduce

trait TFoo:
    fn __copyinit__(out self, other: Self):
        ...

    fn __str__(self) -> String:
        ...

@value
struct Ralph(TFoo):
    alias TYPE = "Ralph"

    fn __str__(self) -> String:
        return self.TYPE

@value
struct Waldo(TFoo):
    alias TYPE = "Waldo"

    fn __str__(self) -> String:
        return self.TYPE

@value
struct Emerson(TFoo):
    alias TYPE = "Emerson"

    fn __str__(self) -> String:
        return self.TYPE

@value
struct Bar[T: TFoo](CollectionElement):
    var foo: T

    fn __init__(out self, foo: T):
        self.foo = foo

    fn __str__(self) -> String:
        return self.foo.__str__()

fn main():
    ralph = Bar(Ralph())
    waldo = Bar(Waldo())
    emerson = Bar(Emerson())

    print(str(ralph))
    print(str(waldo))
    print(str(emerson))

    # _list = List[Bar[TFoo]]()  # Mojo compiler crash

    # _list.append(Bar[Ralph](ralph))
    # _list.append(Bar[Waldo](waldo))
    # _list.append(Bar[Emerson](emerson))

System information

mojo 25.1.0.dev2025011305
magic 0.6.2 - (based on pixi 0.40.0)
Ubuntu 24.10 [boot OS]
@johnsoez4 johnsoez4 added bug Something isn't working mojo-repo Tag all issues with this label labels Jan 13, 2025
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

1 participant