diff options
author | Neelesh Chandola <neelesh.chandola@outlook.com> | 2018-12-09 14:20:01 +0530 |
---|---|---|
committer | Neelesh Chandola <neelesh.chandola@outlook.com> | 2018-12-09 14:20:01 +0530 |
commit | e44641b6cb025b689298584418e91844b1ac5a4a (patch) | |
tree | 235a7f7193791e01b1b3b1deeb449e21b488fd31 | |
parent | d977fc6f320ea7aed97de0d883b6da27f7de61c4 (diff) | |
download | Nim-e44641b6cb025b689298584418e91844b1ac5a4a.tar.gz |
Float values are invalid in enum
-rw-r--r-- | compiler/semtypes.nim | 2 | ||||
-rw-r--r-- | tests/errmsgs/t9908_01.nim (renamed from tests/errmsgs/t9908.nim) | 4 | ||||
-rw-r--r-- | tests/errmsgs/t9908_02.nim | 10 |
3 files changed, 14 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 294cabe47..4cc759e52 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -100,6 +100,8 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = of tyString, tyCString: strVal = v x = counter + of tyFloat..tyFloat128: + localError(c.config, v.info, errOrdinalTypeExpected) else: x = getOrdValue(v) if i != 1: diff --git a/tests/errmsgs/t9908.nim b/tests/errmsgs/t9908_01.nim index fa086517f..b9d37b67b 100644 --- a/tests/errmsgs/t9908.nim +++ b/tests/errmsgs/t9908_01.nim @@ -6,5 +6,5 @@ line: 10 # https://github.com/nim-lang/Nim/issues/9908 type - X = enum - a = ("a", "b") + 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 |