Fixes #12379 (#12591) [backport]

This commit is contained in:
Clyybber 2019-11-04 20:57:14 +01:00 • committed by Andreas Rumpf
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) errorUndeclaredIdentifier(c, n.sons[0].info, typ.sym.name.s)
elif not isOrdinalType(typ): elif not isOrdinalType(typ):
localError(c.config, n.sons[0].info, "selector must be of an ordinal type, float or string") 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 & localError(c.config, n.info, "low(" & $a.sons[0].sym.name.s &
") must be 0 for discriminant") ") must be 0 for discriminant")
elif lengthOrd(c.config, typ) > 0x00007FFF: elif lengthOrd(c.config, typ) > 0x00007FFF:

View file

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

View file

@ -5,7 +5,7 @@ template reject(x) =
static: assert(not compiles(x)) static: assert(not compiles(x))
type 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 KindObj = object
case kind: Kind case kind: Kind
of k1, k2..k3: i32: int32 of k1, k2..k3: i32: int32
@ -13,10 +13,10 @@ type
else: str: string else: str: string
IntObj = object IntObj = object
case kind: int16 case kind: uint8
of low(int16) .. -1: bad: string of low(uint8) .. 127: bad: string
of 0: neutral: string of 128'u8: neutral: string
of 1 .. high(int16): good: string of 129 .. high(uint8): good: string
OtherKind = enum ok1, ok2, ok3, ok4, ok5 OtherKind = enum ok1, ok2, ok3, ok4, ok5
NestedKindObj = object NestedKindObj = object
@ -76,24 +76,25 @@ reject: # elif branches are ignored
elif kind == k4: discard elif kind == k4: discard
else: discard KindObj(kind: kind, str: "3") else: discard KindObj(kind: kind, str: "3")
let intKind = 29'i16 let intKind = 29'u8
accept: accept:
case intKind case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad") of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 0: discard IntObj(kind: intKind, neutral: "neutral") of 128'u8: discard IntObj(kind: intKind, neutral: "neutral")
of 1 .. high(int16): discard IntObj(kind: intKind, good: "good") of 129 .. high(uint8): discard IntObj(kind: intKind, good: "good")
reject: # 0 leaks to else reject: # 0 leaks to else
case intKind case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad") of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 1 .. high(int16): discard IntObj(kind: intKind, good: "good") of 129 .. high(uint8): discard IntObj(kind: intKind, good: "good")
accept: accept:
case intKind case intKind
of low(int16) .. -1: discard IntObj(kind: intKind, bad: "bad") of low(uint8) .. 127: discard IntObj(kind: intKind, bad: "bad")
of 0: discard IntObj(kind: intKind, neutral: "neutral") of 128'u8: discard IntObj(kind: intKind, neutral: "neutral")
of 10, 11 .. high(int16), 1 .. 9: discard IntObj(kind: intKind, good: "good") of 139'u8, 140 .. high(uint8), 129'u8 .. 138'u8: discard IntObj(kind: intKind, good: "good")
accept: accept:
case kind case kind
@ -148,7 +149,7 @@ reject:
case kind: case kind:
of k1: result = KindObj(kind: kind, i32: 1) of k1: result = KindObj(kind: kind, i32: 1)
else: discard else: discard
type type
Kind3 = enum Kind3 = enum
A, B, C, E A, B, C, E
@ -194,4 +195,4 @@ reject:
discard discard
let x: range[0..15] = 1 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 """ discard """
errormsg: "branch initialization with a runtime discriminator only supports ordinal types with 2^16 elements or less." errormsg: "low(kind) must be 0 for discriminant"
line: 13 line: 7
""" """
type type
HoledObj = object HoledObj = object