From ba047d0af80711ddad03f86e30e5a983fb7e2ae1 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 29 May 2026 08:08:42 +0200 Subject: [PATCH] fixes #25693 (#25842) (cherry picked from commit 7813bd8b92824cacec9cddb5152f8c9ed645e03c) --- compiler/sigmatch.nim | 4 +++ tests/template/toverload_over_untyped.nim | 32 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/template/toverload_over_untyped.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index cfe3a5973f..6ae9fe7374 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2474,6 +2474,10 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, return arg elif f.kind == tyStatic and arg.typ.n != nil: return arg.typ.n + elif f.kind == tyUntyped: + # bug #25693: a different overload candidate may have sem-checked the + # operand and left symbols behind; templates expect the pristine AST. + return argOrig else: return argSemantized # argOrig diff --git a/tests/template/toverload_over_untyped.nim b/tests/template/toverload_over_untyped.nim new file mode 100644 index 0000000000..0f734480d6 --- /dev/null +++ b/tests/template/toverload_over_untyped.nim @@ -0,0 +1,32 @@ +discard """ + output: "ok" +""" + +# bug #25693 + +template g(b: untyped) {.dirty.} = + template t: untyped = b + +proc d() = discard @[0] +proc g(_: int) = discard + +proc f(a: var seq[int], _: string) = + let p = @[0] + d() + a = p + +let q = "a" +g: + var a: seq[int] + try: + f(a, q & "1") + except CatchableError: + discard + try: + f(a, q & "1") + except CatchableError: + discard +block: t() +block: t() +echo "ok" +