diff options
author | Jacek Sieka <arnetheduck@gmail.com> | 2020-04-28 19:56:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 19:56:01 +0200 |
commit | 7d6cbf290a5e0cbce14b9926f57221a017f20a4a (patch) | |
tree | f8bf7d55e271571ebbb817ff28858c29e712382b /compiler | |
parent | cd9af6b8040bc72985d457e5169e18ded7c107d6 (diff) | |
download | Nim-7d6cbf290a5e0cbce14b9926f57221a017f20a4a.tar.gz |
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.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 2 | ||||
-rw-r--r-- | compiler/jsgen.nim | 8 | ||||
-rw-r--r-- | compiler/lexer.nim | 6 | ||||
-rw-r--r-- | compiler/renderer.nim | 4 | ||||
-rw-r--r-- | compiler/semfold.nim | 4 | ||||
-rw-r--r-- | compiler/sempass2.nim | 2 |
7 files changed, 14 insertions, 14 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 2e3169665..3fe75d1f3 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -290,7 +290,7 @@ type sfTemplateParam # symbol is a template parameter sfCursor # variable/field is a cursor, see RFC 177 for details sfInjectDestructors # whether the proc needs the 'injectdestructors' transformation - sfNeverRaises # proc can never raise an exception, not even OverflowError + sfNeverRaises # proc can never raise an exception, not even OverflowDefect # or out-of-memory TSymFlags* = set[TSymFlag] diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 6c70ce798..806eca744 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -821,7 +821,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = v.r.add(".") v.r.add(disc.sym.loc.r) genInExprAux(p, it, u, v, test) - let msg = genFieldError(field, disc.sym) + let msg = genFieldDefect(field, disc.sym) let strLit = genStringLiteral(p.module, newStrNode(nkStrLit, msg)) if op.magic == mNot: linefmt(p, cpsStmts, diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 0e9575e9c..27c4e0e2a 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1131,7 +1131,7 @@ proc genCheckedFieldOp(p: PProc, n: PNode, addrTyp: PType, r: var TCompRes) = useMagic(p, "raiseFieldError") useMagic(p, "makeNimstrLit") - let msg = genFieldError(field, disc) + let msg = genFieldDefect(field, disc) lineF(p, "if ($1[$2.$3]$4undefined) { raiseFieldError(makeNimstrLit($5)); }$n", setx.res, tmp, disc.loc.r, if negCheck: ~"!==" else: ~"===", makeJSString(msg)) @@ -2343,7 +2343,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) = if r.kind != resCallee: r.kind = resNone #r.address = nil r.res = nil - + case n.kind of nkSym: genSym(p, n, r) @@ -2398,7 +2398,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) = n.len >= 1: genInfixCall(p, n, r) else: - genCall(p, n, r) + genCall(p, n, r) of nkClosure: gen(p, n[0], r) of nkCurly: genSetConstr(p, n, r) of nkBracket: genArrayConstr(p, n, r) @@ -2602,7 +2602,7 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode = (code, map) = genSourceMap($(code), outFile.string) writeFile(outFile.string & ".map", $(%map)) discard writeRopeIfNotEqual(code, outFile) - + proc myOpen(graph: ModuleGraph; s: PSym): PPassContext = result = newModule(graph, s) diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 9420d7a48..e91a6415a 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -571,7 +571,7 @@ proc getNumber(L: var TLexer, result: var TToken) = try: len = parseBiggestUInt(result.literal, iNumber) except ValueError: - raise newException(OverflowError, "number out of range: " & $result.literal) + raise newException(OverflowDefect, "number out of range: " & $result.literal) if len != result.literal.len: raise newException(ValueError, "invalid integer: " & $result.literal) result.iNumber = cast[int64](iNumber) @@ -581,7 +581,7 @@ proc getNumber(L: var TLexer, result: var TToken) = try: len = parseBiggestInt(result.literal, iNumber) except ValueError: - raise newException(OverflowError, "number out of range: " & $result.literal) + raise newException(OverflowDefect, "number out of range: " & $result.literal) if len != result.literal.len: raise newException(ValueError, "invalid integer: " & $result.literal) result.iNumber = iNumber @@ -607,7 +607,7 @@ proc getNumber(L: var TLexer, result: var TToken) = except ValueError: lexMessageLitNum(L, "invalid number: '$1'", startpos) - except OverflowError, RangeError: + except OverflowDefect, RangeDefect: lexMessageLitNum(L, "number out of range: '$1'", startpos) tokenEnd(result, postPos-1) L.bufpos = postPos diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 8840e08be..cfc5935fa 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -1599,9 +1599,9 @@ proc quoteExpr*(a: string): string {.inline.} = ## can be used for quoting expressions in error msgs. "'" & a & "'" -proc genFieldError*(field: PSym, disc: PSym): string = +proc genFieldDefect*(field: PSym, disc: PSym): string = ## this needs to be in a module accessible by jsgen, ccgexprs, and vm to - ## provide this error msg FieldError; msgs would be better but it does not + ## provide this error msg FieldDefect; msgs would be better but it does not ## import ast result = field.name.s.quoteExpr & " is not accessible using discriminant " & disc.name.s.quoteExpr & " of type " & diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 931ff5554..d24adb979 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -645,9 +645,9 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = discard else: result = magicCall(m, n, g) - except OverflowError: + except OverflowDefect: localError(g.config, n.info, "over- or underflow") - except DivByZeroError: + except DivByZeroDefect: localError(g.config, n.info, "division by zero") of nkAddr: var a = getConstExpr(m, n[0], g) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 55888a3eb..b801f4531 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -752,7 +752,7 @@ proc track(tracked: PEffects, n: PNode) = createTypeBoundOps(tracked, n[0].typ, n.info) else: # A `raise` with no arguments means we're going to re-raise the exception - # being handled or, if outside of an `except` block, a `ReraiseError`. + # being handled or, if outside of an `except` block, a `ReraiseDefect`. # Here we add a `Exception` tag in order to cover both the cases. addEffect(tracked, createRaise(tracked.graph, n), nil) of nkCallKinds: |