Aliasing is hard and we have to watch out not to compile 'x = f(x.a)' into 'f(x.a, addr x)'
This commit is contained in:
Andreas Rumpf 2022-03-20 14:02:44 +01:00 • committed by GitHub
commit 731eabc930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 deletions

View file

@ -91,3 +91,34 @@ proc test(c: Helper): string =
c.formatted
echo test(Helper(isKind: true, formatted: "ok"))
# bug #19613
type
Eth2Digest = object
data: array[42, byte]
BlockId* = object
root*: Eth2Digest
BlockSlotId* = object
bid*: BlockId
slot*: uint64
func init*(T: type BlockSlotId, bid: BlockId, slot: uint64): T =
#debugecho "init ", bid, " ", slot
BlockSlotId(bid: bid, slot: slot)
proc bug19613 =
var x: BlockSlotId
x.bid.root.data[0] = 42
x =
if x.slot > 0:
BlockSlotId.init(x.bid, x.slot)
else:
BlockSlotId.init(x.bid, x.slot)
doAssert x.bid.root.data[0] == 42
bug19613()