Skip to content

Commit 38ad336

Browse files
authored
fix tuple nodes from VM inserting hidden conv to keep old type (#24756)
fixes #24755, refs #24710 Instead of using the node from `indexTypesMatch` which inserts a hidden conv node, just change the type of the node back to the old type directly
1 parent a7711d4 commit 38ad336

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

compiler/semexprs.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType
29512951
let conversion = indexTypesMatch(c, oldType, typ, result)
29522952
# ignore matching error, the goal is just to keep the original type info
29532953
if conversion != nil:
2954-
result = conversion
2954+
result.typ() = oldType
29552955

29562956
proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
29572957
result = n # we don't modify n, but compute the type:
@@ -2982,7 +2982,7 @@ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedT
29822982
let conversion = indexTypesMatch(c, oldType, typ, result)
29832983
# ignore matching error, the goal is just to keep the original type info
29842984
if conversion != nil:
2985-
result = conversion
2985+
result.typ() = oldType
29862986

29872987
include semobjconstr
29882988

@@ -3073,7 +3073,7 @@ proc semExport(c: PContext, n: PNode): PNode =
30733073
proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
30743074
result = semTuplePositionsConstr(c, n, flags, expectedType)
30753075
var tupexp = result
3076-
while tupexp.kind == nkHiddenSubConv: tupexp = tupexp[1]
3076+
while tupexp.kind == nkHiddenSubConv: tupexp = tupexp[1]
30773077
var isTupleType: bool = false
30783078
if tupexp.len > 0: # don't interpret () as type
30793079
internalAssert c.config, tupexp.kind == nkTupleConstr

tests/tuples/tstatictuple.nim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# issue #24755
2+
3+
type
4+
Field = object
5+
FieldS = object
6+
FieldOps = enum
7+
foNeg, foAdd, foSub, foMul, foDiv, foAdj, foToSingle, foToDouble
8+
FieldUnop[Op: static FieldOps, T1] = object
9+
f1: T1
10+
FieldAddSub[S: static tuple, T: tuple] = object
11+
field: T
12+
SomeField = Field | FieldS | FieldUnop | FieldAddSub
13+
SomeField2 = Field | FieldS | FieldUnop | FieldAddSub
14+
15+
template fieldUnop[X:SomeField](o: static FieldOps, x: X): auto =
16+
FieldUnop[o,X](f1: x)
17+
template fieldAddSub[X,Y](sx: static int, x: X, sy: static int, y: Y): auto =
18+
FieldAddSub[(a:sx,b:sy),tuple[a:X,b:Y]](field:(a:x,b:y))
19+
20+
template `:=`*(r: var FieldS, x: SomeField) =
21+
discard
22+
template toSingle(x: SomeField): auto =
23+
fieldUnop(foToSingle, x)
24+
template toDouble(x: SomeField): auto =
25+
fieldUnop(foToDouble, x)
26+
template `+`(x: SomeField, y: SomeField2): auto =
27+
fieldAddSub(1, x, 1, y)
28+
29+
var
30+
fd: Field
31+
fs,fs2: FieldS
32+
33+
fs2 := toSingle(fs.toDouble + fd)

0 commit comments

Comments
 (0)