modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
22.92k stars 2.58k forks source link

[BUG]: mojo crashes when `def __copyinit__` under `struct` #1854

Open junweizeng opened 6 months ago

junweizeng commented 6 months ago

Bug description

mojo crashes on the following code (i.e. test.mojo).

@value
struct a:
    def __copyinit__(inout b, c: Self):

Steps to reproduce

$ mojo build test.mojo
/path/to/test.mojo:3:5: error: cannot define '__copyinit__' as 'def'; 'def' implicitly raises
    def __copyinit__(inout b, c: Self):
    ^~~
    fn
/path/to/test.mojo:2:1: error: duplicate definition of '__copyinit__'
struct a:
^
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: mojo build test.mojo
1.  Crash resolving decl body at loc("/path/to/test.mojo":2:1)
    >> struct a:
       ^........
    >>     def __copyinit__(inout b, c: Self):
       .......................................<
 #0 0x0000560f46e4ce47 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62ae47)
 #1 0x0000560f46e4aa1e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x628a1e)
 #2 0x0000560f46e4d51f (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62b51f)
 #3 0x00007f254fe5c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000560f47252cd8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa30cd8)
 #5 0x0000560f472e3a83 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xac1a83)
 #6 0x0000560f47273b5c (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa51b5c)
 #7 0x0000560f47285563 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa63563)
 #8 0x0000560f47270f99 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa4ef99)
 #9 0x0000560f4727448c (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa5248c)
#10 0x0000560f4728892a (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa6692a)
#11 0x0000560f47288fc8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa66fc8)
#12 0x0000560f47236cfb (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa14cfb)
#13 0x0000560f47237059 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa15059)
#14 0x0000560f46df5e0f (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d3e0f)
#15 0x0000560f46df823b (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d623b)
#16 0x0000560f46df2ddf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d0ddf)
#17 0x0000560f46df165d (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5cf65d)
#18 0x00007f254fe43d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#19 0x00007f254fe43e40 call_init ./csu/../csu/libc-start.c:128:20
#20 0x00007f254fe43e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#21 0x0000560f46df0fae (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5cefae)

System information

- Ubuntu 22.04 LTS
- mojo 24.1.0 (55ec12d6)
- modular 0.5.1 (1b608e3d)
junweizeng commented 6 months ago

Here's a similar code that reproduces the crash:

@value
struct a:
    fn __moveinit__(inout b, c: Self):
junweizeng commented 6 months ago

Another one:

@value
struct a:
    fn __copyinit__(inout b, c: Self):
    fn __copyinit__