summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-06-15 21:17:24 -0700
committerGitHub <noreply@github.com>2020-06-15 21:17:24 -0700
commitfaedb14a167497f96b1499305deb5538e579eeb0 (patch)
treea3f474c88ca246e433f5ec1722ad2be142baa5ba /compiler
parent49033eb5314d7f07e5ecc088dd0933010bb581d8 (diff)
downloadNim-faedb14a167497f96b1499305deb5538e579eeb0.tar.gz
misc cleanups in compiler msgs: use toHumanStr, etc (#14677)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/msgs.nim7
-rw-r--r--compiler/sem.nim6
-rw-r--r--compiler/semstmts.nim3
-rw-r--r--compiler/semtypes.nim5
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
ase consistency part 7' href='/ahoang/Nim/commit/tools/cmerge.nim?h=devel&id=7e0da3e8f7687ba9eb2c24beca7b7a833621d1bc'>7e0da3e8f ^
00a4e19e8 ^
0ea4b71ee ^
7e0da3e8f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40