Skip to content

VM issue with globals and assignments #25208

@nitely

Description

@nitely

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-09-25
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 9f74712
active boot switches: -d:release

Description

Nim 1.6.20 works as expected; the regression is present in Nim +2.0

type Conf = object
  val: int

const defaultConf = Conf(val: 123)

template foo(conf) =
  echo conf.val
  var conf2 = conf
  echo conf2.val

static:
  var conf = defaultConf
  conf = defaultConf  # removing this results in the expected output
  conf.val = 2
  foo(defaultConf)

Current Output

123
2

Expected Output

123
123

Known Workarounds

wrap the static body in a proc.

Additional Information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions