fixes #25942 #25938; type inference for static container type (#25989)

fixes #25942 
fixes #25938

After a successful match to a concrete static T, normalizes an empty
static container literal to the formal payload type before binding it.
This prevents `static[set[empty]]({})` from leaking into the
instantiated proc body.
This commit is contained in:
ringabout
2026-08-03 17:52:04 +08:00
committed by GitHub
parent 5137d273e5
commit 234f01510f
2 changed files with 29 additions and 1 deletions

View File

@@ -2087,7 +2087,18 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
result = typeRel(c, f.base, a, flags)
else:
result = isGeneric
if result != isNone: put(c, f, aOrig)
if result != isNone:
if f.base.kind notin {tyNone, tyGenericParam} and
aOrig.kind == tyStatic and aOrig.n != nil and aOrig.n.typ != nil and
aOrig.n.typ.isEmptyContainer:
# we need to infer the inner type for empty containers
let literal = aOrig.n.copyTree
literal.typ = f.base
let staticArg = newTypeS(tyStatic, c.c, f.base)
staticArg.n = literal
put(c, f, staticArg)
else:
put(c, f, aOrig)
elif aOrig.n != nil and aOrig.n.typ != nil:
result = if f.base.kind != tyNone:
typeRel(c, f.last, aOrig.n.typ, flags)

View File

@@ -457,3 +457,20 @@ block: # bug #22600
var x: c[2]
x.init()
block:
# bug #25938
proc p(h: static set[bool] = {}) =
discard false in h
p()
p({})
block:
# bug #25942
proc p(h: static set[bool]) = discard len(h)
p({})