Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


## Compiler changes

add `--declaredlocs` to show symbol declaration location in messages


## Tool changes
Expand Down
2 changes: 2 additions & 0 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
processOnOffSwitchG(conf, {optStdout}, arg, pass, info)
of "listfullpaths":
processOnOffSwitchG(conf, {optListFullPaths}, arg, pass, info)
of "declaredlocs":
processOnOffSwitchG(conf, {optDeclaredLocs}, arg, pass, info)
of "dynliboverride":
dynlibOverride(conf, switch, arg, pass, info)
of "dynliboverrideall":
Expand Down
6 changes: 4 additions & 2 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type
hintUser, hintUserRaw,
hintExtendedContext,
hintMsgOrigin, # since 1.3.5
hintDeclaredLoc, # since 1.5.1

const
MsgKindToStr*: array[TMsgKind, string] = [
Expand Down Expand Up @@ -159,6 +160,7 @@ const
hintUserRaw: "$1",
hintExtendedContext: "$1",
hintMsgOrigin: "$1",
hintDeclaredLoc: "$1",
]

const
Expand Down Expand Up @@ -186,7 +188,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", "MsgOrigin",
"User", "UserRaw", "ExtendedContext", "MsgOrigin", "DeclaredLoc"
]

const
Expand Down Expand Up @@ -215,7 +217,7 @@ type

proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores}
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext, hintDeclaredLoc}
result[1] = result[2] - {warnProveField, warnProveIndex,
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}
Expand Down
1 change: 1 addition & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type # please make sure we have under 32 options
optDocInternal # generate documentation for non-exported symbols
optMixedMode # true if some module triggered C++ codegen
optListFullPaths # use full paths in toMsgFilename
optDeclaredLocs # show declaration locations in messages
optNoNimblePath
optHotCodeReloading
optDynlibOverrideAll
Expand Down
11 changes: 5 additions & 6 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
{renderNoBody, renderNoComments, renderNoPragmas}))
else:
candidates.add(getProcHeader(c.config, err.sym, prefer))
candidates.addDeclaredLocMaybe(c.config, err.sym)
candidates.add("\n")
let nArg = if err.firstMismatch.arg < n.len: n[err.firstMismatch.arg] else: nil
let nameParam = if err.firstMismatch.formal != nil: err.firstMismatch.formal.name.s else: ""
Expand All @@ -230,9 +231,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
doAssert err.firstMismatch.formal != nil
candidates.add("\n required type for " & nameParam & ": ")
candidates.add typeToString(wanted)
when false:
if wanted.sym != nil:
candidates.add "(" & (c.config $ wanted.sym.info) & ")"
if wanted.sym != nil:
candidates.addDeclaredLocMaybe(c.config, wanted.sym)
candidates.add "\n but expression '"
if err.firstMismatch.kind == kVarNeeded:
candidates.add renderNotLValue(nArg)
Expand All @@ -242,9 +242,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
candidates.add "' is of type: "
var got = nArg.typ
candidates.add typeToString(got)
when false:
if got.sym != nil:
candidates.add "(" & (c.config $ got.sym.info) & ")"
if got.sym != nil:
candidates.addDeclaredLocMaybe(c.config, got.sym)

doAssert wanted != nil
if got != nil: effectProblem(wanted, got, candidates, c)
Expand Down
9 changes: 7 additions & 2 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ proc isIntLit*(t: PType): bool {.inline.} =
proc isFloatLit*(t: PType): bool {.inline.} =
result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit

proc addDeclaredLoc(result: var string, conf: ConfigRef; sym: PSym) =
result.add " [declared in " & conf$sym.info & "]"
proc addDeclaredLoc*(result: var string, conf: ConfigRef; sym: PSym) =
# result.add " [declared in " & conf$sym.info & "]"
result.add " [declared in " & toFileLineCol(conf, sym.info) & "]"

proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; sym: PSym) =
if optDeclaredLocs in conf.globalOptions:
addDeclaredLoc(result, conf, sym)

proc addTypeHeader*(result: var string, conf: ConfigRef; typ: PType; prefer: TPreferedDesc = preferMixed; getDeclarationPath = true) =
result.add typeToString(typ, prefer)
Expand Down
1 change: 1 addition & 0 deletions doc/advopt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Advanced options:
--stdout:on|off output to stdout
--colors:on|off turn compiler messages coloring on|off
--listFullPaths:on|off list full paths in messages
--declaredlocs:on|off show declaration locations in messages
-w:on|off|list, --warnings:on|off|list
turn all warnings on|off or list all available
--warning[X]:on|off turn specific warning X on|off
Expand Down