8000 [BUG] Errors with optional recursive struct definitions · Issue #3293 · modular/modular · GitHub
[go: up one dir, main page]

Skip to content
[BUG] Errors with optional recursive struct definitions #3293
@suahelen

Description

@suahelen

Bug description

I tried to mess around with some tree-structures lately.
Specifically I wanted to implement the references between the nodes with the Optional[T] so I would not have to mess around with unsafe pointers.

Is that something that should fundamentally be avoided or am I just doing something wrong?

Steps to reproduce

Here a minimal sample:

struct Node(CollectionElement):
    var child: Optional[Node]

    fn __init__(inout self):
        self.child =  Optional[Node](None)

    fn __moveinit__(inout self, owned other: Node) -> None:
        self.child = Optional[Node](None)

    fn __copyinit__(inout self, other: Node) -> None:
        self.child = Optional[Node](None)

fn main():
    # var n = Node()

the code compiles like that. When the last line is uncommented the following error appears:

fam@T7129:/mnt/d/projects/mojo-structures$ mojo src/node.🔥 
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:136:4: error: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:67:4: note: function instantiation failed
/mnt/d/projects/mojo-structures/src/node.🔥:14:17: note: call expansion failed
    var n = Node()
                ^
/mnt/d/projects/mojo-structures/src/node.🔥:1:8: note: call expansion failed
struct Node(CollectionElement):
       ^
/__w/modular/modular/open-source/mojo/stdlib/stdlib/collections/optional.mojo:49:8: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:180:8: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:182:35: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:226:8: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:229:31: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:221:8: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:223:39: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/utils/variant.mojo:390:8: note: function instantiation failed
<unknown>:0: note: failed to compile-time evaluate function call
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int.mojo:367:8: note: failed to interpret function @stdlib::builtin::int::Int::__init__(::Int=&,::IntLiteral)
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int.mojo:373:29: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int_literal.mojo:610:40: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int_literal.mojo:725:79: note: failed to interpret operation kgen.int_literal.convert(#kgen.param.expr<get_alignof, #kgen.type<@"node::Node", {"__del__" : (!kgen.pointer<@"node::Node"> owned_in_mem) -> !kgen.none = @"node::Node::__del__(node::Node)"}> : !kgen.type, #kgen.target<triple = "x86_64-unknown-linux-gnu", arch = "znver2", features = "+adx,+aes,+avx,+avx2,+bmi,+bmi2,+clflushopt,+clwb,+clzero,+crc32,+cx16,+cx8,+f16c,+fma,+fsgsbase,+fxsr,+lzcnt,+mmx,+movbe,+mwaitx,+pclmul,+popcnt,+prfchw,+rdpid,+rdpru,+rdrnd,+rdseed,+sahf,+sha,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+sse4a,+ssse3,+wbnoinvd,+x87,+xsave,+xsavec,+xsaveopt,+xsaves", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", relocation_model = "pic", simd_bit_width = 256> : !kgen.target> : !kgen.int_literal)
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int.mojo:373:29: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int_literal.mojo:610:40: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/int_literal.mojo:725:79: note: input must be IntLiteralAttr
mojo: error: failed to run the pass manager```



### System information

```shell
- WSL 2 (Windows 10)
- mojo 2024.7.2305 (a7b124bf)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmojoIssues that are related to mojomojo-repoTag all issues with this label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0