mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
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.
40 lines
598 B
Nim
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() |