You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error: Expected a node of kind nnkEnumTy, got nnkInfix
main.nim
import std/[strutils]
typeEnum=enum a, b, c
EnumRange= b..c
discardparseEnum[EnumRange]("")
Nim Version
2.2.0
Current Output
PS /Users/dawid/Desktop/unfun/netchess/tmp> nim c main
Hint: used config file '/Users/dawid/.choosenim/toolchains/nim-2.2.0/config/nim.cfg' [Conf]
Hint: used config file '/Users/dawid/.choosenim/toolchains/nim-2.2.0/config/config.nims' [Conf]
.......................................................................................
stack trace: (most recent call last)
/Users/dawid/.choosenim/toolchains/nim-2.2.0/lib/std/enumutils.nim(27, 3) genEnumCaseStmt
/Users/dawid/.choosenim/toolchains/nim-2.2.0/lib/core/macros.nim(691, 24) expectKind
/Users/dawid/Desktop/unfun/netchess/tmp/main.nim(7, 29) template/generic instantiation of `parseEnum` from here
/Users/dawid/.choosenim/toolchains/nim-2.2.0/lib/pure/strutils.nim(1323, 18) template/generic instantiation of `genEnumCaseStmt` from here
/Users/dawid/Desktop/unfun/netchess/tmp/main.nim(5, 16) Error: Expected a node of kind nnkEnumTy, got nnkInfix
### Expected Output
_No response_
### Known Workarounds
_No response_
### Additional Information
_No response_
The text was updated successfully, but these errors were encountered:
Implementing it so it only parses the fields in the range would be a new feature, however we could skip the range type or at least give a proper error and restrict to enum and not range.
import std/[strutils, typetraits]
procparseEnum[T: rangeandenum](val: string): T =let val =parseEnum[T.rangeBase](val)
if val notin T.low..T.high:
raise (refValueError)(msg: "Expected a value inside "&$T &" but got "&$val)
T(val)
typeEnum=enum a, b, c
EnumRange= b..c
echoparseEnum[EnumRange]("b")
try:
discardparseEnum[EnumRange]("a")
except:
discardparseEnum[EnumRange]("")
Description
Error: Expected a node of kind nnkEnumTy, got nnkInfix
main.nim
Nim Version
2.2.0
Current Output
The text was updated successfully, but these errors were encountered: