From 1124bb88f87025348ce0a71863dad30d48d6b2c2 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 14 Aug 2026 22:45:17 +0800 Subject: [PATCH] Add tests for nimvm scope handling and undeclared identifiers --- tests/vm/t26048.nim | 9 +++++++++ tests/vm/twhennimvmscope1.nim | 12 ++++++++++++ tests/vm/twhennimvmscope2.nim | 13 +++++++++++++ tests/vm/twhennimvmscope3.nim | 10 ++++++++++ tests/whenstmt/t26044.nim | 16 ++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 tests/vm/t26048.nim create mode 100644 tests/vm/twhennimvmscope1.nim create mode 100644 tests/vm/twhennimvmscope2.nim create mode 100644 tests/vm/twhennimvmscope3.nim create mode 100644 tests/whenstmt/t26044.nim diff --git a/tests/vm/t26048.nim b/tests/vm/t26048.nim new file mode 100644 index 0000000000..7191dac6ce --- /dev/null +++ b/tests/vm/t26048.nim @@ -0,0 +1,9 @@ +# issue #26048, `$` declarations must not leak from `when nimvm` + +type U = object + +when nimvm: + proc `$`(_: U): string = "s" + +var n: U +doAssert $n != "s" diff --git a/tests/vm/twhennimvmscope1.nim b/tests/vm/twhennimvmscope1.nim new file mode 100644 index 0000000000..c535ad3437 --- /dev/null +++ b/tests/vm/twhennimvmscope1.nim @@ -0,0 +1,12 @@ +# issue #23687 + +when nimvm: + proc mytest(a: int) = + echo a +else: + template mytest(a: int) = + echo a + 42 + +proc xxx() = + mytest(100) #[tt.Error + ^ undeclared identifier: 'mytest']# diff --git a/tests/vm/twhennimvmscope2.nim b/tests/vm/twhennimvmscope2.nim new file mode 100644 index 0000000000..70d8319f5a --- /dev/null +++ b/tests/vm/twhennimvmscope2.nim @@ -0,0 +1,13 @@ +# issue #23688 + +when nimvm: + proc mytest(a: int) = + echo a +else: + template mytest(a: untyped) = + echo a + 42 + +proc xxx() = + mytest(100) #[tt.Error + ^ undeclared identifier: 'mytest']# +xxx() diff --git a/tests/vm/twhennimvmscope3.nim b/tests/vm/twhennimvmscope3.nim new file mode 100644 index 0000000000..1b99519db7 --- /dev/null +++ b/tests/vm/twhennimvmscope3.nim @@ -0,0 +1,10 @@ +# issue #13450, example 3 + +proc bar() = + when nimvm: + let y = 1 + else: + let y = 2 + discard y #[tt.Error + ^ undeclared identifier: 'y']# +bar() diff --git a/tests/whenstmt/t26044.nim b/tests/whenstmt/t26044.nim new file mode 100644 index 0000000000..ec21f059ff --- /dev/null +++ b/tests/whenstmt/t26044.nim @@ -0,0 +1,16 @@ +# issue #26044 + +discard """ + cmd: "nim check --hints:off --warnings:off $file" + action: reject + nimout: ''' +t26044.nim(15, 11) Error: undeclared identifier: 'g' +t26044.nim(15, 11) Error: expression 'g' has no type (or is ambiguous) +''' +""" + +proc p = + when nimvm: + var g: int + discard g +p()