Error -> Defect for defects (#13908)

* Error -> Defect for defects

The distinction between Error and Defect is subjective,
context-dependent and somewhat arbitrary, so when looking at an
exception, it's hard to guess what it is - this happens often when
looking at a `raises` list _without_ opening the corresponding
definition and digging through layers of inheritance.

With the help of a little consistency in naming, it's at least possible
to start disentangling the two error types and the standard lib can set
a good example here.
This commit is contained in:
Jacek Sieka 2020-04-28 19:56:01 +02:00 • committed by GitHub
commit 7d6cbf290a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 323 additions and 300 deletions

View file

@ -14,14 +14,14 @@ var x: range[1..10] = 10
try:
x += 1
echo x
except OverflowError, RangeError:
except OverflowDefect, RangeDefect:
expected += 1
echo x
try:
inc x
echo x
except OverflowError, RangeError:
except OverflowDefect, RangeDefect:
expected += 1
echo x
@ -29,14 +29,14 @@ x = 1
try:
x -= 1
echo x
except OverflowError, RangeError:
except OverflowDefect, RangeDefect:
expected += 1
echo x
try:
dec x
echo x
except OverflowError, RangeError:
except OverflowDefect, RangeDefect:
expected += 1
echo x

View file

@ -2,25 +2,25 @@ discard """
action: run
"""
doAssertRaises(OverflowError): discard low(int8) - 1'i8
doAssertRaises(OverflowError): discard high(int8) + 1'i8
doAssertRaises(OverflowError): discard abs(low(int8))
doAssertRaises(DivByZeroError): discard 1 mod 0
doAssertRaises(DivByZeroError): discard 1 div 0
doAssertRaises(OverflowError): discard low(int8) div -1'i8
doAssertRaises(OverflowDefect): discard low(int8) - 1'i8
doAssertRaises(OverflowDefect): discard high(int8) + 1'i8
doAssertRaises(OverflowDefect): discard abs(low(int8))
doAssertRaises(DivByZeroDefect): discard 1 mod 0
doAssertRaises(DivByZeroDefect): discard 1 div 0
doAssertRaises(OverflowDefect): discard low(int8) div -1'i8
doAssertRaises(OverflowError): discard -low(int64)
doAssertRaises(OverflowError): discard low(int64) - 1'i64
doAssertRaises(OverflowError): discard high(int64) + 1'i64
doAssertRaises(OverflowDefect): discard -low(int64)
doAssertRaises(OverflowDefect): discard low(int64) - 1'i64
doAssertRaises(OverflowDefect): discard high(int64) + 1'i64
type E = enum eA, eB
doAssertRaises(OverflowError): discard eA.pred
doAssertRaises(OverflowError): discard eB.succ
doAssertRaises(OverflowDefect): discard eA.pred
doAssertRaises(OverflowDefect): discard eB.succ
doAssertRaises(OverflowError): discard low(int8) * -1
doAssertRaises(OverflowError): discard low(int64) * -1
doAssertRaises(OverflowError): discard high(int8) * 2
doAssertRaises(OverflowError): discard high(int64) * 2
doAssertRaises(OverflowDefect): discard low(int8) * -1
doAssertRaises(OverflowDefect): discard low(int64) * -1
doAssertRaises(OverflowDefect): discard high(int8) * 2
doAssertRaises(OverflowDefect): discard high(int64) * 2
doAssert abs(-1) == 1
doAssert 2 div 2 == 1

View file

@ -1,8 +1,8 @@
block: # bug #2427
var x = 0'u8
dec x # OverflowError
x -= 1 # OverflowError
dec x # OverflowDefect
x -= 1 # OverflowDefect
x = x - 1 # No error
doAssert(x == 253'u8)