# build with nim c -r --passC:"-fsanitize=address,undefined" --passL:"-fsanitize=address,undefined"
# expected: ASan reports heap-use-after-free
type
MData = ref object
tag: int
let nilD = MData(tag: 1)
var slots: seq[MData]
slots.grow(1, nilD) # `grow` move-fills: this slot does not retain `nilD`.
slots[0] = MData(tag: 2) # Frees the shared value.
echo nilD.tag # Reads the freed shared value.
# $ nim --version
# Nim Compiler Version 2.2.10 [Linux: amd64]
# Compiled at 2026-04-24
# Copyright (c) 2006-2026 by Andreas Rumpf
#
# active boot switches: -d:release