(cherry picked from commit 27eb19cc48)
This commit is contained in:
flywind
2020-11-02 15:56:51 +08:00
committed by narimiran
parent 98bd81b4a3
commit e0aa7cf09b
2 changed files with 17 additions and 4 deletions

View File

@@ -733,8 +733,9 @@ proc firstOrd*(conf: ConfigRef; t: PType): Int128 =
if t.len > 0 and t[0] != nil:
result = firstOrd(conf, t[0])
else:
assert(t.n[0].kind == nkSym)
result = toInt128(t.n[0].sym.position)
if t.n.len > 0:
assert(t.n[0].kind == nkSym)
result = toInt128(t.n[0].sym.position)
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink,
tyStatic, tyInferred, tyUserTypeClasses, tyLent:
result = firstOrd(conf, lastSon(t))
@@ -790,8 +791,9 @@ proc lastOrd*(conf: ConfigRef; t: PType): Int128 =
of tyUInt64:
result = toInt128(0xFFFFFFFFFFFFFFFF'u64)
of tyEnum:
assert(t.n[^1].kind == nkSym)
result = toInt128(t.n[^1].sym.position)
if t.n.len > 0:
assert(t.n[^1].kind == nkSym)
result = toInt128(t.n[^1].sym.position)
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink,
tyStatic, tyInferred, tyUserTypeClasses, tyLent:
result = lastOrd(conf, lastSon(t))

11
tests/enum/tenum_self.nim Normal file
View File

@@ -0,0 +1,11 @@
discard """
errormsg: "1 can't be converted to ErrorFoo"
"""
type
Foo = enum
Bar = 0.Foo
ErrorFoo = enum
eBar = 1.ErrorFoo