From c07807bedf1749fa9d3e826d3d736907fefbe568 Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 7 Nov 2020 16:00:41 +0800 Subject: [PATCH] Fix #15706 (#15846) * fix #15706 Underflow not detected when using dec on distinct ranges * fix #15846 first, jsgen even doesn't care of range in this op --- compiler/ccgexprs.nim | 2 +- tests/overflw/tdistinct_range.nim | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/overflw/tdistinct_range.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 1eb6caeb3..a3fbeca5f 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2269,7 +2269,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = initLocExpr(p, e[1], a) initLocExpr(p, e[2], b) - let ranged = skipTypes(e[1].typ, {tyGenericInst, tyAlias, tySink, tyVar, tyLent}) + let ranged = skipTypes(e[1].typ, {tyGenericInst, tyAlias, tySink, tyVar, tyLent, tyDistinct}) let res = binaryArithOverflowRaw(p, ranged, a, b, if underlying.kind == tyInt64: fun64[op] else: fun[op]) diff --git a/tests/overflw/tdistinct_range.nim b/tests/overflw/tdistinct_range.nim new file mode 100644 index 000000000..f53515d45 --- /dev/null +++ b/tests/overflw/tdistinct_range.nim @@ -0,0 +1,6 @@ +discard """ + outputsub: "Error: unhandled exception: over- or underflow [OverflowDefect]" + exitcode: "1" +""" +var x: distinct range[0..5] +dec(x) \ No newline at end of file