summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semtypes.nim2
-rw-r--r--tests/objvariant/tfloatrangeobj.nim1
-rw-r--r--tests/objvariant/trt_discrim.nim33
-rw-r--r--tests/objvariant/trt_discrim_err2.nim4
4 files changed, 21 insertions, 19 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index fd5ee0598..59d856677 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -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:
diff --git a/tests/objvariant/tfloatrangeobj.nim b/tests/objvariant/tfloatrangeobj.nim
index cad2b2aa0..67e886302 100644
--- a/tests/objvariant/tfloatrangeobj.nim
+++ b/tests/objvariant/tfloatrangeobj.nim
@@ -2,6 +2,7 @@ discard """
   output: '''(kind: 2.0, twoStr: "TWO STR")
 (kind: 1.0)
 '''
+disabled: "true"
 """
 type
   FloatRange = range[1.0..3.0]
diff --git a/tests/objvariant/trt_discrim.nim b/tests/objvariant/trt_discrim.nim
index 30ba3d087..95b2a9f76 100644
--- a/tests/objvariant/trt_discrim.nim
+++ b/tests/objvariant/trt_discrim.nim
@@ -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)
\ No newline at end of file
+  let o = Obj(x: x, field: 1)
diff --git a/tests/objvariant/trt_discrim_err2.nim b/tests/objvariant/trt_discrim_err2.nim
index c5352014e..c595bba1b 100644
--- a/tests/objvariant/trt_discrim_err2.nim
+++ b/tests/objvariant/trt_discrim_err2.nim
@@ -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