From 20cba902d8cfda312269db14c85f364c200145d4 Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 23 Sep 2024 16:43:04 +0300 Subject: [PATCH] fix `nil` literal giving itself type `untyped`/`typed` fixes #24164, regression from #20091 --- compiler/semexprs.nim | 2 +- tests/types/ttopdowninference.nim | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 41493b04607db..f5b32637e91e3 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -3314,7 +3314,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType of nkNilLit: if result.typ == nil: result.typ = getNilType(c) - if expectedType != nil: + if expectedType != nil and expectedType.kind notin {tyUntyped, tyTyped}: var m = newCandidate(c, result.typ) if typeRel(m, expectedType, result.typ) >= isSubtype: result.typ = expectedType diff --git a/tests/types/ttopdowninference.nim b/tests/types/ttopdowninference.nim index 2a26e0e34e09d..765761e993ffd 100644 --- a/tests/types/ttopdowninference.nim +++ b/tests/types/ttopdowninference.nim @@ -325,3 +325,9 @@ block: # bug #22180 else: (ref A)(nil) doAssert y.isNil + +block: # issue #24164, related regression + proc foo(x: proc ()) = discard + template bar(x: untyped = nil) = + foo(x) + bar()