Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ proc semResolvedCall(c: PContext, x: var TCandidate,
markUsed(c, info, finalCallee, isGenericInstance = true)
onUse(info, finalCallee, isGenericInstance = true)

if finalCallee == c.p.owner and finalCallee.typ.returnType != nil and
finalCallee.typ.returnType.kind == tyAnything:
localError(c.config, info, "cannot infer type of recursive call")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no fundamental reason the example should fail, ie it could take the type from the non-recursive branch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we have the commonType mechanism to sort out these things.


result = compactVoidArgs(x.call)
instGenericConvertersSons(c, result, x)
markConvertersUsed(c, result)
Expand Down
12 changes: 12 additions & 0 deletions tests/errmsgs/t13736.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
discard """
errormsg: "cannot infer type of recursive call"
line: 8
"""

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

echo foo(3)
Loading