diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-12-11 08:36:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 08:36:15 +0100 |
commit | 03c4231951c1944a33a4b56823f65fe877e5ccb3 (patch) | |
tree | ab2f666d97042c2b9577f67a95a02173198b05a0 | |
parent | cd81f368d184dae6268ccf5f4bdc771a661f4ac1 (diff) | |
parent | 47c38cb98e6cde435fd38565cd374050955610eb (diff) | |
download | Nim-03c4231951c1944a33a4b56823f65fe877e5ccb3.tar.gz |
Merge pull request #9909 from nc-x/fix-regression
Fix enum regression
-rw-r--r-- | compiler/semtypes.nim | 4 | ||||
-rw-r--r-- | tests/errmsgs/t9908_01.nim | 10 | ||||
-rw-r--r-- | tests/errmsgs/t9908_02.nim | 10 |
3 files changed, 24 insertions, 0 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 1e75b563e..f4ff97ba4 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -90,6 +90,8 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = if sonsLen(v) == 2: strVal = v.sons[1] # second tuple part is the string value if skipTypes(strVal.typ, abstractInst).kind in {tyString, tyCString}: + if not isOrdinalType(v.sons[0].typ): + localError(c.config, v.sons[0].info, errOrdinalTypeExpected) x = getOrdValue(v.sons[0]) # first tuple part is the ordinal else: localError(c.config, strVal.info, errStringLiteralExpected) @@ -99,6 +101,8 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = strVal = v x = counter else: + if not isOrdinalType(v.typ): + localError(c.config, v.info, errOrdinalTypeExpected) x = getOrdValue(v) if i != 1: if x != counter: incl(result.flags, tfEnumHasHoles) diff --git a/tests/errmsgs/t9908_01.nim b/tests/errmsgs/t9908_01.nim new file mode 100644 index 000000000..b9d37b67b --- /dev/null +++ b/tests/errmsgs/t9908_01.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "ordinal type expected" +line: 10 +""" + +# https://github.com/nim-lang/Nim/issues/9908 + +type + X = enum + a = ("a", "b") diff --git a/tests/errmsgs/t9908_02.nim b/tests/errmsgs/t9908_02.nim new file mode 100644 index 000000000..7ff3d1ff7 --- /dev/null +++ b/tests/errmsgs/t9908_02.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "ordinal type expected" +line: 10 +""" + +# https://github.com/nim-lang/Nim/pull/9909#issuecomment-445519287 + +type + E = enum + myVal = 80.9 |