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
[Mojo]: Simple python like function crashes REPL #804
Comments
try adding Not sure if it'll work ( cuz I wasn't able to install mojo ), but saw this in the examples |
this is also native mojo code, not just python (note def requires no typing), should ideally work. |
I was able to reproduce this error. It seems that the compiler is not handling correctly the vararg in the function declaration. |
Thanks for filing! Seems like a parser crash. @laszlokindrat can you take a look? |
Thank you for opening this issue! This is a known limitation of the current system, but the compiler shouldn't have crashed; in the next release, it will raise an error message instead. The workaround currently is to pass variadic arguments of dynamic types as def a(borrowed *b): pass |
Can you make Attempt 1: Just print a. 4> def foo(borrowed *a):
5. print(a)
6.
[User] error: Expression [4]:6:10: no matching function in call to 'print':
print(a)
~~~~~^~~
Expression [0]:1:1: candidate not viable: callee expects 0 arguments, but 1 was specified
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'DType'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'String'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'StringRef'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'StringLiteral'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'Bool'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'FloatLiteral'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'Int'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 0 were provided (4 more notes omitted.)
from memory.unsafe import Pointer
^
expression failed to parse (no further compiler diagnostics)
4> Attempt 2: Print length of a 6> def foo(borrowed *a):
7. print(len(a))
8.
[User] error: Expression [5]:6:14: no matching function in call to 'len':
print(len(a))
~~~^~~
Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 1 input parameter but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 1 input parameter but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'String'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'StringRef'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: argument #0 cannot be converted from 'variadic<pointer<!kgen.declref<_"$builtin"::_"$object"::_object>>>' to 'StringLiteral'
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 1 input parameter but 0 were provided
from memory.unsafe import Pointer
^
Expression [0]:1:1: candidate not viable: callee expects 1 input parameter but 0 were provided (3 more notes omitted.)
from memory.unsafe import Pointer
^
expression failed to parse (no further compiler diagnostics)
6> |
We have an issue related this: #793 and we are working on making variadics more ergonomic! The closest thing you can do right now is something like this: def foo(borrowed *a: Int):
print("number of variadic args:", len(VariadicList(a)))
for i in range(len(VariadicList(a))):
print("arg #" + String(i) + ":", a[i]) |
Issue description
The text was updated successfully, but these errors were encountered: