M
Modular•13mo ago
ekjokesunaukya

error: TODO: expressions are not yet supported at the file scope

I get this message when I run this code from docs.
fn add(x: Int, y: Int) -> Int:
return x + y

z = add(1, 2)
print(z)
fn add(x: Int, y: Int) -> Int:
return x + y

z = add(1, 2)
print(z)
Error:
test.mojo:4:1: error: TODO: expressions are not yet supported at the file scope level
z = add(1, 2)
^
test.mojo:4:1: error: use of unknown declaration 'z'
z = add(1, 2)
^
test.mojo:5:1: error: TODO: expressions are not yet supported at the file scope level
print(z)
^
test.mojo:5:7: error: use of unknown declaration 'z'
print(z)
^
test.mojo:4:1: error: TODO: expressions are not yet supported at the file scope level
z = add(1, 2)
^
test.mojo:4:1: error: use of unknown declaration 'z'
z = add(1, 2)
^
test.mojo:5:1: error: TODO: expressions are not yet supported at the file scope level
print(z)
^
test.mojo:5:7: error: use of unknown declaration 'z'
print(z)
^
No description
3 Replies
Jack Clayton
Jack Clayton•13mo ago
Hi @ekjokesunaukya congrats on having the first question! Expressions have to be inside a def or fn so you just have to move it to:
fn add(x: Int, y: Int) -> Int:
return x + y


def main():
z = add(1, 2)
print(z)
fn add(x: Int, y: Int) -> Int:
return x + y


def main():
z = add(1, 2)
print(z)
Support for expressions outside a fn or def (file scope) will be implemented later
ekjokesunaukya
ekjokesunaukya•13mo ago
Thanks for the prompt reply and the help, @Jack Clayton ! Have a great day!
Jack Clayton
Jack Clayton•13mo ago
No worries you too 😄
Want results from more Discord servers?
Add your server