mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
no more guessing where compiler msgs came from (#14317)
This commit is contained in:
@@ -175,6 +175,9 @@ proc mydiv(a, b): int {.raises: [].} =
|
||||
(likewise with other hints and warnings), which is consistent with all other bool flags.
|
||||
(since 1.3.3).
|
||||
- `nim doc -r main` and `nim rst2html -r main` now call openDefaultBrowser
|
||||
- new hint: `--hint:msgOrigin` will show where a compiler msg (hint|warning|error) was generated; this
|
||||
helps in particular when it's non obvious where it came from either because multiple locations generate
|
||||
the same message, or because the message involves runtime formatting.
|
||||
|
||||
## Tool changes
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ type
|
||||
hintSource, hintPerformance, hintStackTrace, hintGCStats,
|
||||
hintGlobalVar, hintExpandMacro,
|
||||
hintUser, hintUserRaw,
|
||||
hintExtendedContext
|
||||
hintExtendedContext,
|
||||
hintMsgOrigin, # since 1.3.5
|
||||
|
||||
const
|
||||
MsgKindToStr*: array[TMsgKind, string] = [
|
||||
@@ -140,6 +141,7 @@ const
|
||||
hintUser: "$1",
|
||||
hintUserRaw: "$1",
|
||||
hintExtendedContext: "$1",
|
||||
hintMsgOrigin: "$1",
|
||||
]
|
||||
|
||||
const
|
||||
@@ -166,7 +168,7 @@ const
|
||||
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
|
||||
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
|
||||
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
|
||||
"User", "UserRaw", "ExtendedContext",
|
||||
"User", "UserRaw", "ExtendedContext", "MsgOrigin",
|
||||
]
|
||||
|
||||
const
|
||||
@@ -192,7 +194,7 @@ proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
||||
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
|
||||
result[1] = result[2] - {warnProveField, warnProveIndex,
|
||||
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
||||
hintSource, hintGlobalVar, hintGCStats}
|
||||
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}
|
||||
result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
|
||||
hintProcessing, hintPattern, hintExecuting, hintLinking, hintCC}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import
|
||||
lineinfos, pathutils
|
||||
import std/private/miscdollars
|
||||
|
||||
type InstantiationInfo = typeof(instantiationInfo())
|
||||
|
||||
proc toCChar*(c: char; result: var string) =
|
||||
case c
|
||||
of '\0'..'\x1F', '\x7F'..'\xFF':
|
||||
@@ -255,6 +257,9 @@ proc toLinenumber*(info: TLineInfo): int {.inline.} =
|
||||
proc toColumn*(info: TLineInfo): int {.inline.} =
|
||||
result = info.col
|
||||
|
||||
proc toFileLineCol(info: InstantiationInfo): string {.inline.} =
|
||||
result.toLocation(info.filename, info.line, info.column + ColOffset)
|
||||
|
||||
proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
|
||||
result.toLocation(toMsgFilename(conf, info), info.line.int, info.col.int + ColOffset)
|
||||
|
||||
@@ -487,7 +492,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
|
||||
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
|
||||
|
||||
proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||
eh: TErrorHandling) =
|
||||
eh: TErrorHandling, info2: InstantiationInfo) {.noinline.} =
|
||||
var
|
||||
title: string
|
||||
color: ForegroundColor
|
||||
@@ -533,36 +538,47 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
|
||||
if conf.hasHint(hintSource):
|
||||
conf.writeSurroundingSrc(info)
|
||||
if conf.hasHint(hintMsgOrigin):
|
||||
styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle, " compiler msg initiated here", KindColor, KindFormat % HintsToStr[ord(hintMsgOrigin) - ord(hintMin)], resetStyle)
|
||||
|
||||
handleError(conf, msg, eh, s)
|
||||
|
||||
proc fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
# this fixes bug #7080 so that it is at least obvious 'fatal'
|
||||
# was executed.
|
||||
conf.m.errorOutputs = {eStdOut, eStdErr}
|
||||
liMessage(conf, info, msg, arg, doAbort)
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, msg, arg, doAbort, info2)
|
||||
|
||||
proc globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
liMessage(conf, info, msg, arg, doRaise)
|
||||
template globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, msg, arg, doRaise, info2)
|
||||
|
||||
proc globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||
liMessage(conf, info, errGenerated, arg, doRaise)
|
||||
template globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, errGenerated, arg, doRaise, info2)
|
||||
|
||||
proc localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
liMessage(conf, info, msg, arg, doNothing)
|
||||
template localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, msg, arg, doNothing, info2)
|
||||
|
||||
proc localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||
liMessage(conf, info, errGenerated, arg, doNothing)
|
||||
template localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, errGenerated, arg, doNothing, info2)
|
||||
|
||||
proc localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
|
||||
localError(conf, info, format % params)
|
||||
template localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, errGenerated, format % params, doNothing, info2)
|
||||
|
||||
proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
liMessage(conf, info, msg, arg, doNothing)
|
||||
template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
liMessage(conf, info, msg, arg, doNothing, info2)
|
||||
|
||||
proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
|
||||
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
||||
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||
writeContext(conf, info)
|
||||
liMessage(conf, info, errInternal, errMsg, doAbort)
|
||||
liMessage(conf, info, errInternal, errMsg, doAbort, info2)
|
||||
|
||||
proc internalError*(conf: ConfigRef; errMsg: string) =
|
||||
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
||||
|
||||
Reference in New Issue
Block a user