produce more helpful error messages when overloading resolution fails

This commit is contained in:
Andreas Rumpf 2018-11-03 15:56:13 +01:00
commit c739b9192f
4 changed files with 18 additions and 8 deletions

View file

@ -739,6 +739,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "hint": conf.globalOptions = conf.globalOptions + {optStyleHint} of "hint": conf.globalOptions = conf.globalOptions + {optStyleHint}
of "error": conf.globalOptions = conf.globalOptions + {optStyleError} of "error": conf.globalOptions = conf.globalOptions + {optStyleError}
else: localError(conf, info, errOffHintsError % arg) else: localError(conf, info, errOffHintsError % arg)
of "showallmismatches":
processOnOffSwitchG(conf, {optShowAllMismatches}, arg, pass, info)
of "cppcompiletonamespace": of "cppcompiletonamespace":
if arg.len > 0: if arg.len > 0:
conf.cppCustomNamespace = arg conf.cppCustomNamespace = arg

View file

@ -74,6 +74,7 @@ type # please make sure we have under 32 options
optIdeTerse # idetools: use terse descriptions optIdeTerse # idetools: use terse descriptions
optNoCppExceptions # use C exception handling even with CPP optNoCppExceptions # use C exception handling even with CPP
optExcessiveStackTrace # fully qualified module filenames optExcessiveStackTrace # fully qualified module filenames
optShowAllMismatches # show all overloading resolution candidates
optWholeProject # for 'doc2': output any dependency optWholeProject # for 'doc2': output any dependency
optMixedMode # true if some module triggered C++ codegen optMixedMode # true if some module triggered C++ codegen
optListFullPaths optListFullPaths

View file

@ -166,20 +166,22 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
prefer = preferModuleInfo prefer = preferModuleInfo
break break
when false:
# we pretend procs are attached to the type of the first # we pretend procs are attached to the type of the first
# argument in order to remove plenty of candidates. This is # argument in order to remove plenty of candidates. This is
# comparable to what C# does and C# is doing fine. # comparable to what C# does and C# is doing fine.
var filterOnlyFirst = false var filterOnlyFirst = false
if optShowAllMismatches notin c.config.globalOptions:
for err in errors: for err in errors:
if err.firstMismatch > 1: if err.firstMismatch > 1:
filterOnlyFirst = true filterOnlyFirst = true
break break
var candidates = "" var candidates = ""
var skipped = 0
for err in errors: for err in errors:
when false: if filterOnlyFirst and err.firstMismatch == 1:
if filterOnlyFirst and err.firstMismatch == 1: continue inc skipped
continue
if err.sym.kind in routineKinds and err.sym.ast != nil: if err.sym.kind in routineKinds and err.sym.ast != nil:
add(candidates, renderTree(err.sym.ast, add(candidates, renderTree(err.sym.ast,
{renderNoBody, renderNoComments, renderNoPragmas})) {renderNoBody, renderNoComments, renderNoPragmas}))
@ -216,7 +218,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
"' is immutable\n") "' is immutable\n")
for diag in err.diagnostics: for diag in err.diagnostics:
candidates.add(diag & "\n") 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) result = (prefer, candidates)
const const

View file

@ -29,6 +29,9 @@ Advanced options:
produce hints or errors for Nim identifiers that produce hints or errors for Nim identifiers that
do not adhere to Nim's official style guide do not adhere to Nim's official style guide
https://nim-lang.org/docs/nep1.html https://nim-lang.org/docs/nep1.html
--showAllMismatches:on|off
show all mismatching candidates in overloading
resolution
--lib:PATH set the system library path --lib:PATH set the system library path
--import:PATH add an automatically imported module --import:PATH add an automatically imported module
--include:PATH add an automatically included module --include:PATH add an automatically included module