diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-06-15 21:17:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 21:17:24 -0700 |
commit | faedb14a167497f96b1499305deb5538e579eeb0 (patch) | |
tree | a3f474c88ca246e433f5ec1722ad2be142baa5ba /compiler | |
parent | 49033eb5314d7f07e5ecc088dd0933010bb581d8 (diff) | |
download | Nim-faedb14a167497f96b1499305deb5538e579eeb0.tar.gz |
misc cleanups in compiler msgs: use toHumanStr, etc (#14677)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/msgs.nim | 7 | ||||
-rw-r--r-- | compiler/sem.nim | 6 | ||||
-rw-r--r-- | compiler/semstmts.nim | 3 | ||||
-rw-r--r-- | compiler/semtypes.nim | 5 |
4 files changed, 9 insertions, 12 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index e27eedd1c..aecaaf405 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -558,12 +558,13 @@ template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = template globalAssert*(conf: ConfigRef; cond: untyped, info: TLineInfo = unknownLineInfo, arg = "") = ## avoids boilerplate if not cond: - const info2 = instantiationInfo(-1, fullPaths = true) var arg2 = "'$1' failed" % [astToStr(cond)] if arg.len > 0: arg2.add "; " & astToStr(arg) & ": " & arg - liMessage(conf, info, errGenerated, arg2, doRaise, info2) + liMessage(conf, info, errGenerated, arg2, doRaise, instLoc()) template globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = + ## `local` means compilation keeps going until errorMax is reached (via `doNothing`), + ## `global` means it stops. liMessage(conf, info, msg, arg, doRaise, instLoc()) template globalError*(conf: ConfigRef; info: TLineInfo, arg: string) = @@ -593,7 +594,7 @@ template internalError*(conf: ConfigRef; errMsg: string) = internalErrorImpl(conf, unknownLineInfo, errMsg, instLoc()) template internalAssert*(conf: ConfigRef, e: bool) = - # xxx merge with globalAssert from PR #14324 + # xxx merge with `globalAssert` if not e: const info2 = instLoc() let arg = info2.toFileLineCol diff --git a/compiler/sem.nim b/compiler/sem.nim index ca5d9c448..a657939a5 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -197,15 +197,13 @@ proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym = suggestDecl(c, n, result) proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym = - proc `$`(kind: TSymKind): string = substr(system.`$`(kind), 2).toLowerAscii - # like newSymS, but considers gensym'ed symbols if n.kind == nkSym: # and sfGenSym in n.sym.flags: result = n.sym if result.kind notin {kind, skTemp}: - localError(c.config, n.info, "cannot use symbol of kind '" & - $result.kind & "' as a '" & $kind & "'") + localError(c.config, n.info, "cannot use symbol of kind '$1' as a '$2'" % + [result.kind.toHumanStr, kind.toHumanStr]) when false: if sfGenSym in result.flags and result.kind notin {skTemplate, skMacro, skParam}: # declarative context, so produce a fresh gensym: diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index a4b4c9362..6ffaa9dda 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -514,8 +514,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = if typ.kind in tyUserTypeClasses and typ.isResolvedUserTypeClass: typ = typ.lastSon if hasEmpty(typ): - localError(c.config, def.info, errCannotInferTypeOfTheLiteral % - ($typ.kind).substr(2).toLowerAscii) + localError(c.config, def.info, errCannotInferTypeOfTheLiteral % typ.kind.toHumanStr) elif typ.kind == tyProc and tfUnresolved in typ.flags: localError(c.config, def.info, errProcHasNoConcreteType % def.renderTree) when false: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 313328385..eba8dd397 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -905,8 +905,7 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = if t.kind == tyTypeDesc and tfUnresolved notin t.flags: t = t.base if t.kind == tyVoid: - const kindToStr: array[tyPtr..tyRef, string] = ["ptr", "ref"] - localError(c.config, n.info, "type '$1 void' is not allowed" % kindToStr[kind]) + localError(c.config, n.info, "type '$1 void' is not allowed" % kind.toHumanStr) result = newOrPrevType(kind, prev, c) var isNilable = false var wrapperKind = tyNone @@ -1400,7 +1399,7 @@ proc semObjectTypeForInheritedGenericInst(c: PContext, n: PNode, t: PType) = proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = if s.typ == nil: localError(c.config, n.info, "cannot instantiate the '$1' $2" % - [s.name.s, ($s.kind).substr(2).toLowerAscii]) + [s.name.s, s.kind.toHumanStr]) return newOrPrevType(tyError, prev, c) var t = s.typ |