Skip to content

Commit

Permalink
just ignore in transf, fix cast too
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jan 22, 2025
1 parent 7b7e6c3 commit d1112d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/semobjconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ proc defaultConstructionError(c: PContext, t: PType, info: TLineInfo) =
proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
var t = semTypeNode(c, n[0], nil)
result = newNodeIT(nkObjConstr, n.info, t)
result.add newNodeIT(nkType, n[0].info, t)
for i in 1..<n.len:
for i in 0..<n.len:
result.add n[i]

if t == nil:
Expand Down
10 changes: 10 additions & 0 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ proc transformSons(c: PTransf, n: PNode, noConstFold = false): PNode =
for i in 0..<n.len:
result[i] = transform(c, n[i], noConstFold)

proc transformSonsAfterType(c: PTransf, n: PNode, noConstFold = false): PNode =
result = newTransNode(n)
assert n.len != 0
result[0] = n[0]
for i in 1..<n.len:
result[i] = transform(c, n[i], noConstFold)

proc newAsgnStmt(c: PTransf, kind: TNodeKind, le: PNode, ri: PNode; isFirstWrite: bool): PNode =
result = newTransNode(kind, ri.info, 2)
result[0] = le
Expand Down Expand Up @@ -1102,6 +1109,9 @@ proc transform(c: PTransf, n: PNode, noConstFold = false): PNode =
result = transformAddrDeref(c, n, {nkAddr, nkHiddenAddr})
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
result = transformConv(c, n)
of nkObjConstr, nkCast:
# don't try to transform type node
result = transformSonsAfterType(c, n)
of nkDiscardStmt:
result = n
if n[0].kind != nkEmpty:
Expand Down
7 changes: 7 additions & 0 deletions tests/template/tgenericobjconstr.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
discard """
matrix: "--skipParentCfg"
"""

# issue #24631

type
Expand All @@ -6,3 +10,6 @@ type

template y(): V[false] = V[false](l: 0)
discard y()

template z(): V[false] = cast[V[false]](V[false](l: 0))
discard z()

0 comments on commit d1112d4

Please sign in to comment.