fixes #25419; lift magic types to typeclasses (#25421)

fixes #25419
This commit is contained in:
ringabout
2026-01-14 23:25:52 +08:00
committed by GitHub
parent c1e381ae8d
commit 40480fe348
2 changed files with 17 additions and 0 deletions

View File

@@ -1845,6 +1845,13 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
let baseType = s.typ.safeSkipTypes(abstractPtrs)
if baseType.kind in {tyObject, tyTuple} and not baseType.n.isNil:
checkForMetaFields(c, baseType.n, hasError)
if s.typ.kind in {tySet, tyArray, tySequence, tyUncheckedArray} and s.typ.elementType.kind == tyNone:
# magic generics are not filled but tyNone is added to its elements by default,
# we lift them to tyBuiltInTypeClass here
s.typ = newTypeS(tyBuiltInTypeClass, c,
newTypeS(s.typ.kind, c))
if not hasError:
checkConstructedType(c.config, s.info, s.typ)
#instAllTypeBoundOp(c, n.info)

View File

@@ -116,3 +116,13 @@ block:
s(something)
s(otherthing, something)
s(something, otherthing)
block:
type
Test = set
Test2 = seq
Test3 = array
doAssert set is Test
doAssert seq is Test2
doAssert array is Test3