From 97c160271ca9e36ec382323735a7cfdaf45de124 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:25:52 +0800 Subject: [PATCH] fixes #25419; lift magic types to typeclasses (#25421) fixes #25419 (cherry picked from commit 40480fe3481cf833ed927f83a177d43046e7c37d) --- compiler/semstmts.nim | 11 +++++++++-- tests/types/tissues_types.nim | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 3146d8efbc..f91a6c83d3 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -617,7 +617,7 @@ proc checkDefineType(c: PContext; v: PSym; t: PType) = # no distinct types for generic define skipped.excl tyDistinct if t.skipTypes(skipped).kind notin typeKinds: - let name = + let name = case v.magic of mStrDefine: "strdefine" of mIntDefine: "intdefine" @@ -1829,6 +1829,13 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = x[0].kind in {nkObjectTy, nkTupleTy}) ): 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) @@ -2640,7 +2647,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, # we need to add a result symbol for them maybeAddResult(c, s, n) - + trackProc(c, s, s.ast[bodyPos]) else: if (s.typ.returnType != nil and s.kind != skIterator): diff --git a/tests/types/tissues_types.nim b/tests/types/tissues_types.nim index 6bb1258f4d..d5eb60be42 100644 --- a/tests/types/tissues_types.nim +++ b/tests/types/tissues_types.nim @@ -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