mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
implement semgnrc for tuple and object type nodes (#22709)
fixes #22699
This commit is contained in:
@@ -457,8 +457,47 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||
of nkIdent: a = n[i]
|
||||
else: illFormedAst(n, c.config)
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(c, a), c))
|
||||
of nkObjectTy, nkTupleTy, nkTupleClassTy:
|
||||
discard
|
||||
of nkTupleTy:
|
||||
for i in 0..<n.len:
|
||||
var a = n[i]
|
||||
case a.kind:
|
||||
of nkCommentStmt, nkNilLit, nkSym, nkEmpty: continue
|
||||
of nkIdentDefs:
|
||||
checkMinSonsLen(a, 3, c.config)
|
||||
a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
|
||||
a[^1] = semGenericStmt(c, a[^1], flags, ctx)
|
||||
for j in 0..<a.len-2:
|
||||
addTempDecl(c, getIdentNode(c, a[j]), skField)
|
||||
else:
|
||||
illFormedAst(a, c.config)
|
||||
of nkObjectTy:
|
||||
if n.len > 0:
|
||||
openScope(c)
|
||||
for i in 0..<n.len:
|
||||
result[i] = semGenericStmt(c, n[i], flags, ctx)
|
||||
closeScope(c)
|
||||
of nkRecList:
|
||||
for i in 0..<n.len:
|
||||
var a = n[i]
|
||||
case a.kind:
|
||||
of nkCommentStmt, nkNilLit, nkSym, nkEmpty: continue
|
||||
of nkIdentDefs:
|
||||
checkMinSonsLen(a, 3, c.config)
|
||||
a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
|
||||
a[^1] = semGenericStmt(c, a[^1], flags, ctx)
|
||||
for j in 0..<a.len-2:
|
||||
addTempDecl(c, getIdentNode(c, a[j]), skField)
|
||||
of nkRecCase, nkRecWhen:
|
||||
n[i] = semGenericStmt(c, a, flags, ctx)
|
||||
else:
|
||||
illFormedAst(a, c.config)
|
||||
of nkRecCase:
|
||||
checkSonsLen(n[0], 3, c.config)
|
||||
n[0][^2] = semGenericStmt(c, n[0][^2], flags+{withinTypeDesc}, ctx)
|
||||
n[0][^1] = semGenericStmt(c, n[0][^1], flags, ctx)
|
||||
addTempDecl(c, getIdentNode(c, n[0][0]), skField)
|
||||
for i in 1..<n.len:
|
||||
n[i] = semGenericStmt(c, n[i], flags, ctx)
|
||||
of nkFormalParams:
|
||||
checkMinSonsLen(n, 1, c.config)
|
||||
for i in 1..<n.len:
|
||||
|
||||
6
tests/generics/mtypenodes.nim
Normal file
6
tests/generics/mtypenodes.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
# issue #22699
|
||||
|
||||
type Private = distinct int
|
||||
|
||||
proc chop*[T](x: int): int =
|
||||
cast[int](cast[tuple[field: Private]](x))
|
||||
@@ -7,7 +7,7 @@ false
|
||||
'''
|
||||
"""
|
||||
|
||||
import mbind_bracket, mclosed_sym, mdotlookup, mmodule_same_as_proc
|
||||
import mbind_bracket, mclosed_sym, mdotlookup, mmodule_same_as_proc, mtypenodes
|
||||
|
||||
|
||||
block tbind_bracket:
|
||||
@@ -57,3 +57,7 @@ block tmodule_same_as_proc:
|
||||
proc test[T](t: T) =
|
||||
mmodule_same_as_proc"a"
|
||||
test(0)
|
||||
|
||||
block ttypenodes:
|
||||
# issue #22699
|
||||
doAssert chop[bool](42) == 42
|
||||
|
||||
Reference in New Issue
Block a user