Skip to content

Commit a52482c

Browse files
authored
Merge pull request scala#6612 from adriaanm/pr6580-pt1
Faster implicit search: lazier error messages
2 parents 8951701 + a595114 commit a52482c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ trait ContextErrors {
9797

9898
def issueTypeError(err: AbsTypeError)(implicit context: Context): Unit = { context.issue(err) }
9999

100-
def typeErrorMsg(found: Type, req: Type) = "type mismatch" + foundReqMsg(found, req)
100+
def typeErrorMsg(context: Context, found: Type, req: Type) =
101+
if (context.openImplicits.nonEmpty && !settings.XlogImplicits.value) "type mismatch"
102+
else "type mismatch" + foundReqMsg(found, req)
101103
}
102104

103105
def notAnyRefMessage(found: Type): String = {
@@ -208,7 +210,7 @@ trait ContextErrors {
208210
assert(!foundType.isErroneous, s"AdaptTypeError - foundType is Erroneous: $foundType")
209211
assert(!req.isErroneous, s"AdaptTypeError - req is Erroneous: $req")
210212

211-
issueNormalTypeError(callee, withAddendum(callee.pos)(typeErrorMsg(foundType, req)))
213+
issueNormalTypeError(callee, withAddendum(callee.pos)(typeErrorMsg(context, foundType, req)))
212214
infer.explainTypes(foundType, req)
213215
}
214216

@@ -1106,7 +1108,7 @@ trait ContextErrors {
11061108
}
11071109

11081110
def NoBestExprAlternativeError(tree: Tree, pt: Type, lastTry: Boolean) = {
1109-
issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(tree.symbol.tpe, pt)))
1111+
issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(context, tree.symbol.tpe, pt)))
11101112
setErrorOnLastTry(lastTry, tree)
11111113
}
11121114

@@ -1373,7 +1375,7 @@ trait ContextErrors {
13731375
sm"""|Note that implicit conversions are not applicable because they are ambiguous:
13741376
|${coreMsg}are possible conversion functions from $found to $req"""
13751377
}
1376-
typeErrorMsg(found, req) + (
1378+
typeErrorMsg(context, found, req) + (
13771379
if (explanation == "") "" else "\n" + explanation
13781380
)
13791381
}

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ trait Implicits {
410410

411411
def pos = if (pos0 != NoPosition) pos0 else tree.pos
412412

413-
def failure(what: Any, reason: String, pos: Position = this.pos): SearchResult = {
413+
@inline final def failure(what: Any, reason: => String, pos: Position = this.pos): SearchResult = {
414414
if (settings.XlogImplicits)
415415
reporter.echo(pos, what+" is not a valid implicit value for "+pt+" because:\n"+reason)
416416
SearchFailure
@@ -673,7 +673,7 @@ trait Implicits {
673673
val itree1 = if (isBlackbox(info.sym)) suppressMacroExpansion(itree0) else itree0
674674
typingLog("considering", typeDebug.ptTree(itree1))
675675

676-
def fail(reason: String): SearchResult = failure(itree0, reason)
676+
@inline def fail(reason: => String): SearchResult = failure(itree0, reason)
677677
def fallback = typed1(itree1, EXPRmode, wildPt)
678678
try {
679679
val itree2 = if (!isView) fallback else pt match {
@@ -734,7 +734,7 @@ trait Implicits {
734734
info.sym.fullLocationString, itree2.symbol.fullLocationString))
735735
else {
736736
val tvars = undetParams map freshVar
737-
def ptInstantiated = pt.instantiateTypeParams(undetParams, tvars)
737+
val ptInstantiated = pt.instantiateTypeParams(undetParams, tvars)
738738

739739
if (matchesPt(itree3.tpe, ptInstantiated, undetParams)) {
740740
if (tvars.nonEmpty)

0 commit comments

Comments
 (0)