Fixes #12379 (#12591) [backport]

This commit is contained in:
Clyybber
2019-11-04 20:57:14 +01:00
committed by Andreas Rumpf
parent 558ecd1ca6
commit cf5c3f2400
4 changed files with 21 additions and 19 deletions

View File

@@ -635,7 +635,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
errorUndeclaredIdentifier(c, n.sons[0].info, typ.sym.name.s)
elif not isOrdinalType(typ):
localError(c.config, n.sons[0].info, "selector must be of an ordinal type, float or string")
elif firstOrd(c.config, typ) != 0:
if firstOrd(c.config, typ) != 0:
localError(c.config, n.info, "low(" & $a.sons[0].sym.name.s &
") must be 0 for discriminant")
elif lengthOrd(c.config, typ) > 0x00007FFF:

View File

@@ -2,6 +2,7 @@ discard """
output: '''(kind: 2.0, twoStr: "TWO STR")
(kind: 1.0)
'''
disabled: "true"
"""
type
FloatRange = range[1.0..3.0]

View File

@@ -5,7 +5,7 @@ template reject(x) =
static: assert(not compiles(x))
type
Kind = enum k1 = 2, k2 = 33, k3 = 84, k4 = 278, k5 = 1000 # Holed enum work!
Kind = enum k1 = 0, k2 = 33, k3 = 84, k4 = 278, k5 = 1000 # Holed enum work! #No they don't..
KindObj = object
case kind: Kind
of k1, k2..k3: i32: int32
@@ -13,10 +13,10 @@ type
else: str: string
IntObj = object
case kind: int16
of low(int16) .. -1: bad: string
of 0: neutral: string
of 1 .. high(int16): good: string
case kind: uint8
of low(uint8) .. 127: bad: string
of 128'u8: neutral: string
of 129 .. high(uint8): good: string
OtherKind = enum ok1, ok2, ok3, ok4, ok5
NestedKindObj = object
@@ -76,24 +76,25 @@ reject: # elif branches are ignored
elif kind == k4: discard
else: discard KindObj(kind: kind, str: "3")
let intKind = 29'i16
let intKind = 29'u8
accept:
case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad")
of 0: discard IntObj(kind: intKind, neutral: "neutral")
of 1 .. high(int16): discard IntObj(kind: intKind, good: "good")
of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 128'u8: discard IntObj(kind: intKind, neutral: "neutral")
of 129 .. high(uint8): discard IntObj(kind: intKind, good: "good")
reject: # 0 leaks to else
case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad")
of 1 .. high(int16): discard IntObj(kind: intKind, good: "good")
of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 129 .. high(uint8): discard IntObj(kind: intKind, good: "good")
accept:
case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad")
of 0: discard IntObj(kind: intKind, neutral: "neutral")
of 10, 11 .. high(int16), 1 .. 9: discard IntObj(kind: intKind, good: "good")
of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 128'u8: discard IntObj(kind: intKind, neutral: "neutral")
of 139'u8, 140 .. high(uint8), 129'u8 .. 138'u8: discard IntObj(kind: intKind, good: "good")
accept:
case kind
@@ -148,7 +149,7 @@ reject:
case kind:
of k1: result = KindObj(kind: kind, i32: 1)
else: discard
type
Kind3 = enum
A, B, C, E
@@ -194,4 +195,4 @@ reject:
discard
let x: range[0..15] = 1
let o = Obj(x: x, field: 1)
let o = Obj(x: x, field: 1)

View File

@@ -1,6 +1,6 @@
discard """
errormsg: "branch initialization with a runtime discriminator only supports ordinal types with 2^16 elements or less."
line: 13
errormsg: "low(kind) must be 0 for discriminant"
line: 7
"""
type
HoledObj = object