From eaf35fd9e5db635a4c7ab88913305cf08c8c0afc Mon Sep 17 00:00:00 2001 From: metagn Date: Thu, 5 Dec 2024 06:57:58 +0300 Subject: [PATCH 1/3] make getType node for generic inst have skipped type fixes #24503, refs #22655 --- compiler/vmdeps.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 2a088ac9645b4..1803d4d6217fe 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -135,8 +135,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; if inst: if allowRecursion: result = mapTypeToAstR(t.skipModifier, info) - # keep original type info for getType calls on the output node: - result.typ() = t + # result.typ can be tyGenericBody, give it a proper type: + result.typ() = t.skipModifier else: result = newNodeX(nkBracketExpr) #result.add mapTypeToAst(t.last, info) @@ -145,8 +145,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; result.add mapTypeToAst(a, info) else: result = mapTypeToAstX(cache, t.skipModifier, info, idgen, inst, allowRecursion) - # keep original type info for getType calls on the output node: - result.typ() = t + # result.typ can be tyGenericBody, give it a proper type: + result.typ() = t.skipModifier of tyGenericBody: if inst: result = mapTypeToAstR(t.typeBodyImpl, info) From 71a60de5885a54fee6d7be01acb99d5d2ef46659 Mon Sep 17 00:00:00 2001 From: metagn Date: Thu, 5 Dec 2024 07:02:55 +0300 Subject: [PATCH 2/3] fix getType on object/distinct types giving bare generic sym fixes #24503, refs #22655, refs #24509 --- compiler/vmdeps.nim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 1803d4d6217fe..ba5cde8fc1535 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -135,8 +135,6 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; if inst: if allowRecursion: result = mapTypeToAstR(t.skipModifier, info) - # result.typ can be tyGenericBody, give it a proper type: - result.typ() = t.skipModifier else: result = newNodeX(nkBracketExpr) #result.add mapTypeToAst(t.last, info) @@ -145,8 +143,6 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; result.add mapTypeToAst(a, info) else: result = mapTypeToAstX(cache, t.skipModifier, info, idgen, inst, allowRecursion) - # result.typ can be tyGenericBody, give it a proper type: - result.typ() = t.skipModifier of tyGenericBody: if inst: result = mapTypeToAstR(t.typeBodyImpl, info) @@ -161,7 +157,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; result = newNodeX(nkDistinctTy) result.add mapTypeToAst(t.skipModifier, info) else: - if allowRecursion or t.sym == nil: + if allowRecursion or t.sym == nil or tfFromGeneric in t.flags: result = mapTypeToBracket("distinct", mDistinct, t, info) else: result = atomicType(t.sym) @@ -185,7 +181,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; else: result.add newNodeI(nkEmpty, info) else: - if allowRecursion or t.sym == nil: + if allowRecursion or t.sym == nil or tfFromGeneric in t.flags: result = newNodeIT(nkObjectTy, if t.n.isNil: info else: t.n.info, t) result.add newNodeI(nkEmpty, info) if t.baseClass == nil: From 686139c19264b352b173e423a9b6a572d3709312 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 6 Dec 2024 17:07:43 +0300 Subject: [PATCH 3/3] test restricting invalid cases --- compiler/vmdeps.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index ba5cde8fc1535..9bd93d08480d0 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -157,7 +157,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; result = newNodeX(nkDistinctTy) result.add mapTypeToAst(t.skipModifier, info) else: - if allowRecursion or t.sym == nil or tfFromGeneric in t.flags: + if allowRecursion or t.sym == nil or + (tfFromGeneric in t.flags and t.sym.typ.kind == tyGenericBody): result = mapTypeToBracket("distinct", mDistinct, t, info) else: result = atomicType(t.sym) @@ -181,7 +182,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; else: result.add newNodeI(nkEmpty, info) else: - if allowRecursion or t.sym == nil or tfFromGeneric in t.flags: + if allowRecursion or t.sym == nil or + (tfFromGeneric in t.flags and t.sym.typ.kind == tyGenericBody): result = newNodeIT(nkObjectTy, if t.n.isNil: info else: t.n.info, t) result.add newNodeI(nkEmpty, info) if t.baseClass == nil: