summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-01-22 18:43:33 +0000
committerMartin Odersky <odersky@gmail.com>2008-01-22 18:43:33 +0000
commite45c740e239be4a43dca38f26fd02c29204fa7ae (patch)
treec26fb6414ab295063de6b97a49a777a4a18d23a3
parent9090138f76db5d8dabe952b8a576a8127122d4a3 (diff)
downloadscala-e45c740e239be4a43dca38f26fd02c29204fa7ae.tar.gz
scala-e45c740e239be4a43dca38f26fd02c29204fa7ae.tar.bz2
scala-e45c740e239be4a43dca38f26fd02c29204fa7ae.zip
fixed #347. Added option -Xlog-implicits.
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala9
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala13
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
}