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] Parser crashes when struct has parameterized and slice __getitem__ overloads #2383

Closed
bgreni opened this issue Apr 22, 2024 · 1 comment
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-repo Tag all issues with this label

Comments

@bgreni
Copy link

bgreni commented Apr 22, 2024

Bug description

If a struct has both a simple parameterized __getitem__ implementation, as well as one that takes a slice. Attempting to use the slice operator will result in a parser crash.

Blocking completion of #2337 since List and String are both sliceable.

Steps to reproduce

struct Foo:
    var l: List[Int]
    fn __init__(inout self):
        self.l = List[Int](1,2,3)

    fn __getitem__[T: Intable](self, i: T) -> Int:
        return self.l[int(i)]
        
    fn __getitem__(self, s: Slice) -> List[Int]:
        return self.l[s]

fn main():
    var t = Foo()
    var x = t[1:]
Stack dump:
0.      Program arguments: mojo run playground.mojo
1.      Crash resolving decl body at loc("/Users/bgreni/Coding/mojo/playground.mojo":16:4)
    >> fn main():
          ^......
    >>     var t = Foo()
    >>     var x = t[1:]
       .................<
2.      Crash parsing statement at loc("/Users/bgreni/Coding/mojo/playground.mojo":18:5)
    >>     var x = t[1:]
           ^............<
 #0 0x000000010416d384 llvm_strlcpy (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000c5384)
 #1 0x000000010416b670 llvm_strlcpy (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000c3670)
 #2 0x000000010416da70 llvm_strlcpy (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000c5a70)
 #3 0x00000001878cfa24 (/usr/lib/system/libsystem_platform.dylib+0x180467a24)
 #4 0x0000000104425480 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037d480)
 #5 0x0000000104458ac4 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003b0ac4)
 #6 0x0000000104488460 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003e0460)
 #7 0x0000000104487c70 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003dfc70)
 #8 0x0000000104422f14 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037af14)
 #9 0x0000000104422104 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037a104)
#10 0x0000000104423360 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037b360)
#11 0x0000000104483b34 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003dbb34)
#12 0x0000000104423f80 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037bf80)
#13 0x0000000104423e34 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10037be34)
#14 0x00000001044662a4 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003be2a4)
#15 0x000000010446a2fc __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003c22fc)
#16 0x000000010445c0a0 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003b40a0)
#17 0x000000010449959c __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003f159c)
#18 0x0000000104491b44 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003e9b44)
#19 0x0000000104491944 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003e9944)
#20 0x0000000104437c54 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10038fc54)
#21 0x0000000104445b54 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10039db54)
#22 0x0000000104445f94 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10039df94)
#23 0x000000010444e27c __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003a627c)
#24 0x000000010444e4a4 __jit_debug_register_code (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1003a64a4)
#25 0x00000001040b4680 _mh_execute_header (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10000c680)
#26 0x00000001040c5c54 _mh_execute_header (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10001dc54)
#27 0x00000001040af73c _mh_execute_header (/Users/bgreni/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10000773c)
#28 0x00000001875250e0 
mojo crashed!
Please file a bug report.
[50819:1801860:20240422,171805.990832:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)

System information

OS: Sonoma 14.1 Apple M3
mojo 2024.4.1618 (37a3e965)
modular 0.7.0 (487c2f88)
@bgreni bgreni added bug Something isn't working mojo Issues that are related to mojo labels Apr 22, 2024
@JoeLoser JoeLoser added the crash label Apr 23, 2024
@ematejska ematejska added the mojo-repo Tag all issues with this label label Apr 29, 2024
@bgreni
Copy link
Author

bgreni commented May 8, 2024

This appears to have been resolved so closing this issue

tested with: mojo 2024.5.622 (d9dc4c21)

@bgreni bgreni closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants