fixes #25208; generates a copy for opcLdConst in the assignments (#25211)

fixes #25208


```nim
type Conf = object
  val: int

const defaultConf = Conf(val: 123)
static:
  var conf: Conf
  conf = defaultConf
```

```nim
# opcLdConst is now always valid. We produce the necessary copy in the
# assignments now:
```

A `opcLdConst` is generated for `defaultConf` in `conf = defaultConf`.
According to the comment above, we need to handle the copy for
assignments of `opcLdConst`
This commit is contained in:
ringabout
2025-10-17 00:22:06 +08:00
committed by GitHub
parent 8f3bdb6951
commit f009ea6c3e
2 changed files with 25 additions and 3 deletions

View File

@@ -794,3 +794,22 @@ block: # bug #23925
static: # bug #21353
var s: proc () = default(proc ())
doAssert s == nil
# bug #25208
type Conf = object
val: int
const defaultConf = Conf(val: 123)
template foo2323(conf) =
assert conf.val == 123
var conf2 = conf
assert conf2.val == 123
static:
var conf: Conf = defaultConf
conf = defaultConf # removing this results in the expected output
conf.val = 2
foo2323(defaultConf)