Skip to content

Commit

Permalink
fix nil literal giving itself type untyped/typed
Browse files Browse the repository at this point in the history
fixes #24164, regression from #20091
  • Loading branch information
metagn committed Sep 23, 2024
1 parent d51d887 commit 20cba90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/types/ttopdowninference.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 20cba90

Please sign in to comment.