modularml / mojo

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

[BUG] Compiler crash in recursive function #3471

Open MikeInnes opened 1 month ago

MikeInnes commented 1 month ago

Bug description

Mojo 24.4.0 fails to run the following code, instead producing a compiler error.

def func(i):
    if i == 1:
        return []
    else:
        return [func(i-1)]

def main():
    print(func(1))
``` ➜ mojo mojo --version mojo 24.4.0 (59977802) ➜ mojo mojo run hello.mojo /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: error: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: note: call expansion failed - no concrete specializations /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:119:4: note: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:131:57: note: call expansion failed - no concrete specializations /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:91:4: note: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:107:18: note: call expansion failed - no concrete specializations /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:128:8: note: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:129:22: note: call expansion failed - no concrete specializations /Users/mike/projects/mojo/hello.mojo:7:5: note: function instantiation failed def main(): ^ /Users/mike/projects/mojo/hello.mojo:8:15: note: call expansion failed - no concrete specializations print(func(1)) ^ /Users/mike/projects/mojo/hello.mojo:1:5: note: function instantiation failed def func(i): ^ /Users/mike/projects/mojo/hello.mojo:5:16: note: call expansion failed - no concrete specializations return [func(i-1)] ^ /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/object.mojo:758:8: note: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:44:16: note: call expansion failed - no concrete specializations /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/object.mojo:771:12: note: function instantiation failed /Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/constrained.mojo:34:6: note: constraint failed: cannot convert nested list element to object mojo: error: failed to run the pass manager ```

Steps to reproduce

Paste the code above into test.mojo and run with mojo run test.mojo.

System information

No response

ematejska commented 1 month ago

reproduces with mojo 2024.9.1605 (900128df)

ematejska commented 1 month ago

not a regression from 24.5