mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 12:07:51 +00:00
produce more helpful error messages when overloading resolution fails
This commit is contained in:
@@ -739,6 +739,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||
of "hint": conf.globalOptions = conf.globalOptions + {optStyleHint}
|
||||
of "error": conf.globalOptions = conf.globalOptions + {optStyleError}
|
||||
else: localError(conf, info, errOffHintsError % arg)
|
||||
of "showallmismatches":
|
||||
processOnOffSwitchG(conf, {optShowAllMismatches}, arg, pass, info)
|
||||
of "cppcompiletonamespace":
|
||||
if arg.len > 0:
|
||||
conf.cppCustomNamespace = arg
|
||||
|
||||
@@ -74,6 +74,7 @@ type # please make sure we have under 32 options
|
||||
optIdeTerse # idetools: use terse descriptions
|
||||
optNoCppExceptions # use C exception handling even with CPP
|
||||
optExcessiveStackTrace # fully qualified module filenames
|
||||
optShowAllMismatches # show all overloading resolution candidates
|
||||
optWholeProject # for 'doc2': output any dependency
|
||||
optMixedMode # true if some module triggered C++ codegen
|
||||
optListFullPaths
|
||||
|
||||
@@ -166,20 +166,22 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
prefer = preferModuleInfo
|
||||
break
|
||||
|
||||
when false:
|
||||
# we pretend procs are attached to the type of the first
|
||||
# argument in order to remove plenty of candidates. This is
|
||||
# comparable to what C# does and C# is doing fine.
|
||||
var filterOnlyFirst = false
|
||||
# we pretend procs are attached to the type of the first
|
||||
# argument in order to remove plenty of candidates. This is
|
||||
# comparable to what C# does and C# is doing fine.
|
||||
var filterOnlyFirst = false
|
||||
if optShowAllMismatches notin c.config.globalOptions:
|
||||
for err in errors:
|
||||
if err.firstMismatch > 1:
|
||||
filterOnlyFirst = true
|
||||
break
|
||||
|
||||
var candidates = ""
|
||||
var skipped = 0
|
||||
for err in errors:
|
||||
when false:
|
||||
if filterOnlyFirst and err.firstMismatch == 1: continue
|
||||
if filterOnlyFirst and err.firstMismatch == 1:
|
||||
inc skipped
|
||||
continue
|
||||
if err.sym.kind in routineKinds and err.sym.ast != nil:
|
||||
add(candidates, renderTree(err.sym.ast,
|
||||
{renderNoBody, renderNoComments, renderNoPragmas}))
|
||||
@@ -216,7 +218,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
"' is immutable\n")
|
||||
for diag in err.diagnostics:
|
||||
candidates.add(diag & "\n")
|
||||
|
||||
if skipped > 0:
|
||||
candidates.add($skipped & " other mismatching symbols have been " &
|
||||
" suppressed; compile with --showAllMismatches:on to see them\n")
|
||||
result = (prefer, candidates)
|
||||
|
||||
const
|
||||
|
||||
@@ -29,6 +29,9 @@ Advanced options:
|
||||
produce hints or errors for Nim identifiers that
|
||||
do not adhere to Nim's official style guide
|
||||
https://nim-lang.org/docs/nep1.html
|
||||
--showAllMismatches:on|off
|
||||
show all mismatching candidates in overloading
|
||||
resolution
|
||||
--lib:PATH set the system library path
|
||||
--import:PATH add an automatically imported module
|
||||
--include:PATH add an automatically included module
|
||||
|
||||
Reference in New Issue
Block a user