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

(cherry picked from commit ddd83f8d8a)
This commit is contained in:
ringabout
2025-03-26 03:42:40 +08:00
committed by narimiran
parent f8ab76ba61
commit 3a8b7d987b
2 changed files with 22 additions and 2 deletions

View File

@@ -2254,7 +2254,8 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc) =
proc genConv(p: BProc, e: PNode, d: var TLoc) =
let destType = e.typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
if sameBackendTypeIgnoreRange(destType, e[1].typ):
let srcType = e[1].typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
if sameBackendTypeIgnoreRange(destType, srcType):
expr(p, e[1], d)
else:
genSomeCast(p, e, d)

View File

@@ -1,11 +1,12 @@
discard """
matrix: "--mm:refc; --mm:arc"
output: '''
it's nil
@[1, 2, 3]
'''
"""
import macros
import std/[options, macros]
block anontuples:
@@ -209,3 +210,21 @@ block: # tuple unpacking assignment with underscore
doAssert (a, b) == (6, 2)
(b, _) = (7, 8)
doAssert (a, b) == (6, 7)
# bug #24800
type
B[T] = object
case r: bool
of false:
v: ref int
of true:
x: T
U = ref object of RootObj
method y(_: U) {.base.} =
var s = default(B[tuple[f: B[int], w: B[int]]])
discard some(s.x)
proc foo =
var s = U()
y(s)