From 985b1125b1e55e74daba8ed7207d9f0b66e416aa Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 3 Jul 2026 01:51:08 +0800 Subject: [PATCH] fixes genMagicExpr: handle mAsgn for Isolated[T] with primitive types in tuple assignment (#25955) Explicit `=sink` calls such as `Isolated[T].=sink` can delegate to a field type like `float`, which has no attached sink op. In that case `replaceHookMagic` leaves the builtin `mAsgn` call in place. `genMagicExpr` did not lower that shape, which caused the regression. Mapping `=sink` to `nkSinkAsgn` and other builtin assignment hooks to `nkAsgn`. --- compiler/ccgexprs.nim | 7 +++++++ tests/arc/tisolated_primitive.nim | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/arc/tisolated_primitive.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 171d656230..df50d93954 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2940,6 +2940,13 @@ proc genEnumToStr(p: BProc, e: PNode, d: var TLoc) = proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = case op + of mAsgn: + let kind = if e[0].sym.name.s == "=sink": nkSinkAsgn else: nkAsgn + let lhs = e[1].skipHiddenAddr + let n = newTreeI(kind, e.info, lhs, e[2]) + n.typ = e.typ + cow(p, e[2]) + genAsgn(p, n, fastAsgn = kind != nkAsgn) of mOr, mAnd: genAndOr(p, e, d, op) of mNot..mUnaryMinusF64: unaryArith(p, e, d, op) of mUnaryMinusI..mAbsI: unaryArithOverflow(p, e, d, op) diff --git a/tests/arc/tisolated_primitive.nim b/tests/arc/tisolated_primitive.nim new file mode 100644 index 0000000000..05e760b155 --- /dev/null +++ b/tests/arc/tisolated_primitive.nim @@ -0,0 +1,12 @@ +# Issue: genMagicExpr: mAsgn internal error when using Isolated[T] with primitive types +# in tuple assignment to pointer dereference + +import std/isolation + +proc main() = + var x: ptr Isolated[float] + x = cast[ptr Isolated[float]](alloc0(sizeof(Isolated[float]))) + x[] = isolate(42.0) + dealloc(x) + +main()