mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-17 13:02:47 +00:00
fixes 25713; Allow addr of object variant's discriminant under uncheckedAssign (#25714)
```nim
type
K = enum
k1,k2
Variant = object
case kind: K
of k1:
discard
of k2:
discard
proc a(x: var K) = discard
proc b(x: ptr K) = discard
var x = Variant(kind: k1)
{.cast(uncheckedAssign).}:
# must be within uncheckedAssign to work
a(x.kind)
b(addr x.kind)
```
(cherry picked from commit 184d423779)
This commit is contained in:
committed by
narimiran
parent
484bb6c398
commit
f4fe7c8b55
@@ -35,7 +35,9 @@ proc semAddr(c: PContext; n: PNode): PNode =
|
||||
let x = semExprWithType(c, n)
|
||||
if x.kind == nkSym:
|
||||
x.sym.flags.incl(sfAddrTaken)
|
||||
if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}:
|
||||
let aa = isAssignable(c, x)
|
||||
if aa notin {arLValue, arLocalLValue, arAddressableConst, arLentValue} and
|
||||
(aa != arDiscriminant or c.inUncheckedAssignSection <= 0):
|
||||
localError(c.config, n.info, errExprHasNoAddress)
|
||||
result.add x
|
||||
result.typ() = makePtrType(c, x.typ.skipTypes({tySink}))
|
||||
|
||||
@@ -27,9 +27,11 @@ t.curr = TokenObject(kind: Token.foo, foo: "foo")
|
||||
echo "SUCCESS"
|
||||
|
||||
proc passToVar(x: var Token) = discard
|
||||
proc passToPtr(x: ptr Token) = discard
|
||||
|
||||
{.cast(uncheckedAssign).}:
|
||||
passToVar(t.curr.kind)
|
||||
passToPtr(addr t.curr.kind)
|
||||
|
||||
t.curr = TokenObject(kind: t.curr.kind, foo: "abc")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user