Skip to content

Commit b019388

Browse files
committed
transf: keep distinct object conversions
Conversion that convert to or from distinct types (including conversions between different distinct types) are now kept.
1 parent e9c0d5a commit b019388

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler/sem/transf.nim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,10 @@ proc transformConv(c: PTransf, n: PNode): PNode =
627627
of tyObject:
628628
let diff = inheritanceDiff(dest, source)
629629
if diff == 0 or diff == high(int):
630-
result = transform(c, n[1])
631-
result.typ = n.typ
630+
if sameType(n.typ, n[1].typ):
631+
result = transform(c, n[1])
632+
else:
633+
result = transformSons(c, n)
632634
else:
633635
result = newTreeIT(
634636
if diff < 0: nkObjUpConv else: nkObjDownConv,
@@ -638,8 +640,11 @@ proc transformConv(c: PTransf, n: PNode): PNode =
638640
of tyObject:
639641
let diff = inheritanceDiff(dest, source)
640642
if diff == 0 or diff == high(int):
641-
result = transform(c, n[1])
642-
result.typ = n.typ
643+
if sameType(n.typ, n[1].typ):
644+
# the conversion doesn't modify the type, drop it
645+
result = transform(c, n[1])
646+
else:
647+
result = transformSons(c, n)
643648
else:
644649
result = newTreeIT(
645650
if diff < 0: nkObjUpConv else: nkObjDownConv,

0 commit comments

Comments
 (0)