summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-09-02 10:56:51 +0200
committerAraq <rumpf_a@web.de>2019-09-02 10:56:51 +0200
commit2396f0ee71a939d6305c829610dfb24f55e53c1c (patch)
treea43e2b54dc7bb96cb2d32890c4888d106c03ba28
parente76568764698be7561501c4809e996f3f1608f74 (diff)
downloadNim-2396f0ee71a939d6305c829610dfb24f55e53c1c.tar.gz
make test green
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--compiler/semfold.nim5
-rw-r--r--tests/range/tcompiletime_range_checks.nim86
3 files changed, 52 insertions, 41 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 643580ff2..2d33c742b 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -149,7 +149,7 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus =
       (srcBaseTyp.kind in IntegralTypes):
     if targetTyp.isOrdinalType:
       if src.kind in nkCharLit..nkUInt64Lit and
-          src.intVal notin firstOrd(c.config, targetTyp)..lastOrd(c.config, targetTyp):
+          src.getInt notin firstOrd(c.config, targetTyp)..lastOrd(c.config, targetTyp):
         result = convNotInRange
       elif src.kind in nkFloatLit..nkFloat64Lit and
           (classify(src.floatVal) in {fcNan, fcNegInf, fcInf} or
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index bfb5077d6..a1732ebb4 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -206,8 +206,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode =
   of mSubI: result = foldSub(getInt(a), getInt(b), n, g)
   of mMulI: result = foldMul(getInt(a), getInt(b), n, g)
   of mMinI:
-    if getInt(a) > getInt(b): result = newIntNodeT(getInt64(b), n, g)
-    else: result = newIntNodeT(getInt64(a), n, g)
+    let argA = getInt(a)
+    let argB = getInt(b)
+    result = newIntNodeT(if argA < argB: argA else: argB, n, g)
   of mMaxI:
     let argA = getInt(a)
     let argB = getInt(b)
diff --git a/tests/range/tcompiletime_range_checks.nim b/tests/range/tcompiletime_range_checks.nim
index ea61fd88d..37095e0b7 100644
--- a/tests/range/tcompiletime_range_checks.nim
+++ b/tests/range/tcompiletime_range_checks.nim
@@ -1,42 +1,52 @@
-template reject(e) =
-  static: assert(not compiles(e))
-
-template accept(e) =
-  static: assert(compiles(e))
+discard """
+  cmd: "nim check --hint[Processing]:off --hint[Conf]:off $file"
+  errormsg: "18446744073709551615 can't be converted to int8"
+  nimout: '''tcompiletime_range_checks.nim(36, 21) Error: 2147483648 can't be converted to int32
+tcompiletime_range_checks.nim(37, 23) Error: -1 can't be converted to uint64
+tcompiletime_range_checks.nim(38, 34) Error: 255 can't be converted to FullNegativeRange
+tcompiletime_range_checks.nim(39, 34) Error: 18446744073709551615 can't be converted to HalfNegativeRange
+tcompiletime_range_checks.nim(40, 34) Error: 300 can't be converted to FullPositiveRange
+tcompiletime_range_checks.nim(41, 30) Error: 101 can't be converted to UnsignedRange
+tcompiletime_range_checks.nim(42, 32) Error: -9223372036854775808 can't be converted to SemiOutOfBounds
+tcompiletime_range_checks.nim(44, 22) Error: nan can't be converted to int32
+tcompiletime_range_checks.nim(46, 23) Error: 1e+100 can't be converted to uint64
+tcompiletime_range_checks.nim(49, 22) Error: 18446744073709551615 can't be converted to int64
+tcompiletime_range_checks.nim(50, 22) Error: 18446744073709551615 can't be converted to int32
+tcompiletime_range_checks.nim(51, 22) Error: 18446744073709551615 can't be converted to int16
+tcompiletime_range_checks.nim(52, 21) Error: 18446744073709551615 can't be converted to int8
+  '''
+"""
 
 type
-  UnsignedRange   = 0'u64 .. 100'u64
-  SemiOutOfBounds = 0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64
-  FullOutOfBounds = 0x8000000000000000'u64 .. 0x8000000000000200'u64
-
-  FullNegativeRange = -200 .. -100
-  HalfNegativeRange = -50 .. 50
-  FullPositiveRange = 100 .. 200
-
-reject(int32(0x80000000'i64))
-accept(int32(0x7fffffff'i64))
-
-reject(uint64(-1'i64))
-accept(uint64(0'i64))
-
-reject(FullNegativeRange(0xff'u32))
-reject(HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range.
-accept(HalfNegativeRange(25'u64))
-reject(FullPositiveRange(300'u64))
-
-accept(UnsignedRange(50'u64))
-reject(UnsignedRange(101'u64))
-
-accept(SemiOutOfBounds(0x7ffffffffffffe00'i64))
-reject(SemiOutOfBounds(0x8000000000000000'i64))  #
-accept(SemiOutOfBounds(0x8000000000000000'u64))  # the last two literals have internally the same `intVal`.
-
-reject(int32(NaN))
-reject(int64(1e100))
-reject(uint64(1e100))
+  UnsignedRange* = range[0'u64 .. 100'u64]
+  SemiOutOfBounds* = range[0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64]
+  FullOutOfBounds* = range[0x8000000000000000'u64 .. 0x8000000000000200'u64]
+
+  FullNegativeRange* = range[-200 .. -100]
+  HalfNegativeRange* = range[-50 .. 50]
+  FullPositiveRange* = range[100 .. 200]
+
+let acceptA* = int32(0x7fffffff'i64)
+let acceptB* = (uint64(0'i64))
+let acceptD* = (HalfNegativeRange(25'u64))
+let acceptE* = (UnsignedRange(50'u64))
+let acceptF* = (SemiOutOfBounds(0x7ffffffffffffe00'i64))
+let acceptH* = (SemiOutOfBounds(0x8000000000000000'u64))
+
+let rejectA* = int32(0x80000000'i64)
+let rejectB* = (uint64(-1'i64))
+let rejectC* = (FullNegativeRange(0xff'u32))
+let rejectD* = (HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range.
+let rejectE* = (FullPositiveRange(300'u64))
+let rejectF* = (UnsignedRange(101'u64))
+let rejectG* = (SemiOutOfBounds(0x8000000000000000'i64))  #
+
+let rejectH* = (int32(NaN))
+let rejectI* = (int64(1e100))
+let rejectJ* = (uint64(1e100))
 
 # removed cross checks from tarithm.nim
-reject(int64(0xFFFFFFFFFFFFFFFF'u64))
-reject(int32(0xFFFFFFFFFFFFFFFF'u64))
-reject(int16(0xFFFFFFFFFFFFFFFF'u64))
-reject( int8(0xFFFFFFFFFFFFFFFF'u64))
+let rejectK* = (int64(0xFFFFFFFFFFFFFFFF'u64))
+let rejectL* = (int32(0xFFFFFFFFFFFFFFFF'u64))
+let rejectM* = (int16(0xFFFFFFFFFFFFFFFF'u64))
+let rejectN* = (int8(0xFFFFFFFFFFFFFFFF'u64))