Skip to content

Enable -Xlog-implicits by default for whitebox macro exceptions #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.12.x
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,18 @@ trait Implicits {
}
}

if (context.reporter.hasErrors)
fail("hasMatchingSymbol reported error: " + context.reporter.firstError.get.errMsg)
else if (itree3.isErroneous)
if (context.reporter.hasErrors) {
val msg = context.reporter.firstError.get.errMsg
val isTopLevelWhiteboxMacro = info.sym.isMacro && !isBlackbox(info.sym) && msg.contains("during macro expansion") && context.openImplicits.lengthCompare(1) == 0
if (isTopLevelWhiteboxMacro) {
val saved = settings.XlogImplicits.value
if (info.sym.isMacro && !isBlackbox(info.sym) && msg.contains("during macro expansion") && context.openImplicits.lengthCompare(1) == 0) settings.XlogImplicits.value = true
try fail("exception typechecking implicit candidate (a whitebox macro): " + msg)
finally settings.XlogImplicits.value = saved
} else {
fail("error typechecking implicit candidate: " + msg)
}
} else if (itree3.isErroneous)
fail("error typechecking implicit candidate")
else if (isLocalToCallsite && !hasMatchingSymbol(itree2))
fail("candidate implicit %s is shadowed by %s".format(
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,10 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
case ex: AbortMacroException => MacroGeneratedAbort(expandee, ex)
case ex: ControlThrowable => throw ex
case ex: TypeError => MacroGeneratedTypeError(expandee, ex)
case NonFatal(_) => MacroGeneratedException(expandee, realex)
case NonFatal(_) =>
if (typer.context.isSearchingForImplicitParam)
typer.context.openImplicits
MacroGeneratedException(expandee, realex)
case fatal => throw fatal
}
} finally {
Expand Down