summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-05-10 11:30:57 +0300
committerGitHub <noreply@github.com>2024-05-10 10:30:57 +0200
commitc101490a0c3422cde5a6d2fd686e5ff5feb7237f (patch)
treeddad3cbe0c3ff72cf34c1099d247d5cb377e1775 /tests
parent1eb9aac2f7a8469a682528a0d63128d599fabae7 (diff)
downloadNim-c101490a0c3422cde5a6d2fd686e5ff5feb7237f.tar.gz
remove bad type inference behavior for enum identifiers (#23588)
refs
https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750

In #20091 a bad kind of type inference was mistakenly left in where if
an identifier `abc` had an expected type of an enum type `Enum`, and
`Enum` had a member called `abc`, the identifier would change to be that
enum member. This causes bugs where a local symbol can have the same
name as an enum member but have a different value. I had assumed this
behavior was removed since but it wasn't, and CI seems to pass having it
removed.

A separate PR needs to be made for the 2.0 branch because these lines
were moved around during a refactoring in #23123 which is not in 2.0.
Diffstat (limited to 'tests')
-rw-r--r--tests/lookups/tenumlocalsym.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/lookups/tenumlocalsym.nim b/tests/lookups/tenumlocalsym.nim
new file mode 100644
index 000000000..575227c07
--- /dev/null
+++ b/tests/lookups/tenumlocalsym.nim
@@ -0,0 +1,22 @@
+block:
+  type Enum = enum a, b
+
+  block:
+    let a = b
+    let x: Enum = a
+    doAssert x == b
+  
+block:
+  type
+    Enum = enum
+      a = 2
+      b = 10
+
+  iterator items2(): Enum =
+    for a in [a, b]:
+      yield a
+
+  var s = newSeq[Enum]()
+  for i in items2():
+    s.add i
+  doAssert s == @[a, b]