Skip to content

Commit ddd83f8

Browse files
authored
fixes #24800; Invalid C code generation with a method, case object in refc (#24809)
fixes #24800 This PR avoids a conversion from `sink T` to `T` I will add a test case
1 parent 8e36fb0 commit ddd83f8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler/ccgexprs.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,8 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc) =
26382638

26392639
proc genConv(p: BProc, e: PNode, d: var TLoc) =
26402640
let destType = e.typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
2641-
if sameBackendTypeIgnoreRange(destType, e[1].typ):
2641+
let srcType = e[1].typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
2642+
if sameBackendTypeIgnoreRange(destType, srcType):
26422643
expr(p, e[1], d)
26432644
else:
26442645
genSomeCast(p, e, d)

tests/tuples/ttuples_various.nim

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
discard """
2+
matrix: "--mm:refc; --mm:arc"
23
output: '''
34
it's nil
45
@[1, 2, 3]
56
'''
67
"""
78

8-
import macros
9+
import std/[options, macros]
910

1011

1112
block anontuples:
@@ -209,3 +210,21 @@ block: # tuple unpacking assignment with underscore
209210
doAssert (a, b) == (6, 2)
210211
(b, _) = (7, 8)
211212
doAssert (a, b) == (6, 7)
213+
214+
# bug #24800
215+
type
216+
B[T] = object
217+
case r: bool
218+
of false:
219+
v: ref int
220+
of true:
221+
x: T
222+
U = ref object of RootObj
223+
224+
method y(_: U) {.base.} =
225+
var s = default(B[tuple[f: B[int], w: B[int]]])
226+
discard some(s.x)
227+
228+
proc foo =
229+
var s = U()
230+
y(s)

0 commit comments

Comments
 (0)