nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.44k stars 1.47k forks source link

Compiler crash with auto return type and recursion #13736

Open metagn opened 4 years ago

metagn commented 4 years ago

Example

proc foo(n: int): auto =
  if n < 5:
    return foo(n + 1)
  else:
    return 9

echo foo(3)

Current Output

Error: internal error: getTypeDescAux(tyUntyped)

Expected Output

Error: cannot infer type of recursive call

Additional Information

proc foo(n: int): auto =
  if n < 5:
    foo(n + 1) # Error: type mismatch: got <untyped> but expected 'int literal(9)'
  else:
    9

echo foo(3)
$ nim -v
Nim Compiler Version 1.0.6
bung87 commented 4 years ago

workaround exchange if else branch, make first branch has concrete type