From e45c740e239be4a43dca38f26fd02c29204fa7ae Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 22 Jan 2008 18:43:33 +0000 Subject: fixed #347. Added option -Xlog-implicits. --- src/compiler/scala/tools/nsc/Settings.scala | 1 + src/compiler/scala/tools/nsc/typechecker/Infer.scala | 9 +++++++-- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 ++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index c1373c59d4..90246cead5 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -108,6 +108,7 @@ class Settings(error: String => Unit) { val Xchecknull = BooleanSetting ("-Xcheck-null", "Emit warning on selection of nullable reference") val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions and assumptions") val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions") + val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more info on why some implicits are not applicable") val Xnojline = new BooleanSetting("-Xnojline", "Do not use JLine for editing").hideToIDE val nouescape = BooleanSetting ("-Xno-uescape", "Disables handling of \\u unicode escapes") val plugin = MultiStringSetting("-Xplugin", "file", "Load a plugin from a file") diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index c4eba1f7b5..bf5c599ae8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -503,8 +503,13 @@ trait Infer { // check first whether type variables can be fully defined from // expected result type. if (!isWeaklyCompatible(restpe.instantiateTypeParams(tparams, tvars), pt)) { - throw new DeferredNoInstance(() => - "result type " + normalize(restpe) + " is incompatible with expected type " + pt) +// just wait and instantiate form the arguments. +// that way, we can try to apply an implicit conversion afterwards. +// This case could happen if restpe is not fully defined, so that +// search for an implicit from it to pt fails because of an ambiguity. +// See #0347. Therefore, the following two lines are commented out. +// throw new DeferredNoInstance(() => +// "result type " + normalize(restpe) + " is incompatible with expected type " + pt) } for (tvar <- tvars) if (!isFullyDefined(tvar)) tvar.constr.inst = NoType diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index cace90f489..6d57902b4b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3313,9 +3313,9 @@ trait Typers { self: Analyzer => else Select(gen.mkAttributedQualifier(info.pre), info.name) } // println("typed impl?? "+info.name+":"+info.tpe+" ==> "+tree+" with "+pt) - def fail(reason: String, sym1: Symbol, sym2: Symbol): Tree = { - if (settings.debug.value) - println(tree+" is not a valid implicit value because:\n"+reason + sym1+" "+sym2) + def fail(reason: String): Tree = { + if (settings.XlogImplicits.value) + inform(tree+" is not a valid implicit value for "+pt+" because:\n"+reason) EmptyTree } try { @@ -3340,9 +3340,12 @@ trait Typers { self: Analyzer => } if (tree2.tpe.isError) EmptyTree else if (hasMatchingSymbol(tree1)) tree2 - else fail("syms differ: ", tree1.symbol, info.sym) + else if (settings.XlogImplicits.value) + fail("candidate implicit "+info.sym+info.sym.locationString+ + " is shadowed by other implicit: "+tree1.symbol+tree1.symbol.locationString) + else EmptyTree } catch { - case ex: TypeError => fail(ex.getMessage(), NoSymbol, NoSymbol) + case ex: TypeError => fail(ex.getMessage()) } } else EmptyTree } -- cgit v1.2.3