summary refs log tree commit diff stats
path: root/lib/std
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2022-02-04 20:47:03 +0800
committerGitHub <noreply@github.com>2022-02-04 13:47:03 +0100
commit33bfe5b12cf771072d93d7316945f3f5e6c727ff (patch)
treeadf81a92c523fe898f1b5321dac48492af8d9636 /lib/std
parent772ed5eff29671b1e99ca17b63c646b341c88123 (diff)
downloadNim-33bfe5b12cf771072d93d7316945f3f5e6c727ff.tar.gz
fix parseEnum cannot parse enum with const fields (#19466)
fix #19463
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/enumutils.nim9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/std/enumutils.nim b/lib/std/enumutils.nim
index 81e602ad5..b7d2b9f89 100644
--- a/lib/std/enumutils.nim
+++ b/lib/std/enumutils.nim
@@ -14,7 +14,7 @@ from typetraits import OrdinalEnum, HoleyEnum
 
 macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
             userMin, userMax: static[int], normalizer: static[proc(s :string): string]): untyped =
-  # generates a case stmt, which assigns the correct enum field given
+  # Generates a case stmt, which assigns the correct enum field given
   # a normalized string comparison to the `argSym` input.
   # string normalization is done using passed normalizer.
   # NOTE: for an enum with fields Foo, Bar, ... we cannot generate
@@ -49,7 +49,12 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
       of nnkIntLit:
         fStr = f[0].strVal
         fNum = f[1].intVal
-      else: error("Invalid tuple syntax!", f[1])
+      else:
+        let fAst = f[0].getImpl
+        if fAst.kind == nnkStrLit:
+          fStr = fAst.strVal
+        else:
+          error("Invalid tuple syntax!", f[1])
     else: error("Invalid node for enum type `" & $f.kind & "`!", f)
     # add field if string not already added
     if fNum >= userMin and fNum <= userMax: