Files
Nim/tests/objvariant/tconstvariants.nim
ringabout 5abd21dfa5 fixes #25123; fixes #11862; Case object from compileTime proc unable to be passed as static param (#25224)
fixes #25123; fixes #11862

follow up https://github.com/nim-lang/Nim/pull/24442
ref https://github.com/nim-lang/Nim/pull/24441

> To fix this, fields from inactive branches are now detected in
semmacrosanity.annotateType (called in fixupTypeAfterEval) and marked to
prevent the codegen of their assignments. In
https://github.com/nim-lang/Nim/pull/24441 these fields were excluded
from the resulting node, but this causes issues when the node is
directly supposed to go back into the VM, for example as const values. I
don't know if this is the only case where this happens, so I wasn't sure
about how to keep that implementation working.

Object variants fields coming from inactive branches from VM are now
flagged `nfPreventCg`. We can ignore them, as done by the C backends.
2025-10-16 18:22:46 +02:00

40 lines
598 B
Nim

import std/macros
# bug #11862
type
Kind = enum kOne, kTwo
Thing = object
case kind: Kind
of kOne:
v1: int
of kTwo:
v2: int
macro magic(): untyped =
var b = Thing(kind: kOne, v1: 3)
quote do:
`b`
const c = magic()
# bug #25123
type V = object
case a: bool
of false: discard
of true: t: int
proc s(): V {.compileTime.} = discard
proc h(_: V) = discard
proc e(m: static[V]) = h(m)
template j(m: static[V]) = h(m)
macro r(m: static[V]) = h(m)
e(s())
j(s())
r(s())
s().e()
s().j()
s().r()