From 02da2cf4ae64908c9b7bb1b249a5975b18fa637c Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 29 Jul 2026 22:38:57 +0800 Subject: [PATCH] fixes #13736; Compiler crash with auto return type and recursion --- compiler/semcall.nim | 4 ++++ tests/errmsgs/t13736.nim | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/errmsgs/t13736.nim diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 38b88ee7d2..f29af17777 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -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") + result = compactVoidArgs(x.call) instGenericConvertersSons(c, result, x) markConvertersUsed(c, result) diff --git a/tests/errmsgs/t13736.nim b/tests/errmsgs/t13736.nim new file mode 100644 index 0000000000..3625b034a5 --- /dev/null +++ b/tests/errmsgs/t13736.nim @@ -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)