ModularM
Modular3y ago
12 replies
sora

Should the language server warn about this case?

Consider the following code:
fn f() -> Int:
  <body>

Mojo language server doesn't produce a type error when body doesn't contain a return. There are cases where this makes sense, like when <body> contains only pass or .... However, for the majority of cases, this clearly won't type check. So, I'm not sure if it's a bug or intended behaviour.

FYI, Python language server like pyright produces the following error message:
def f() -> int:
#          ^^^ Function with declared return type "int" must return value on all code paths
  a = 1
Was this page helpful?