misc cleanups in compiler msgs: use toHumanStr, etc (#14677)

This commit is contained in:
Timothee Cour
2020-06-15 21:17:24 -07:00
committed by GitHub
parent 49033eb531
commit faedb14a16
4 changed files with 9 additions and 12 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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:

View File

@@ -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