aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-09-06 22:15:47 +0200
committerMartin Odersky <odersky@gmail.com>2013-09-06 22:15:47 +0200
commit2aa0615594744a7fd92f5f4d017b47e5c42a793a (patch)
tree90e4458cf2cbfdc03152588eebacb031513197ac /src/dotty/tools/dotc/typer/Typer.scala
parentf7ab848229e8b9b0de1b719725816209aa1271c8 (diff)
downloaddotty-2aa0615594744a7fd92f5f4d017b47e5c42a793a.tar.gz
dotty-2aa0615594744a7fd92f5f4d017b47e5c42a793a.tar.bz2
dotty-2aa0615594744a7fd92f5f4d017b47e5c42a793a.zip
Improvements in implicits error reporting
Plus a few bugfixes for implicits
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 9815015c1..7519cdd73 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -26,6 +26,7 @@ import util.Positions._
import util.SourcePosition
import collection.mutable
import annotation.tailrec
+import Implicits._
import language.implicitConversions
trait TyperContextOps { ctx: Context => }
@@ -946,7 +947,7 @@ class Typer extends Namer with Applications with Implicits {
def adaptOverloaded(ref: TermRef) = {
val altDenots = ref.denot.alternatives
val alts = altDenots map (alt =>
- TermRef.withSym(ref.prefix, alt.symbol.asTerm))
+ TermRef.withSym(ref.prefix, alt.symbol.asTerm).withDenot(alt))
def expectedStr = err.expectedTypeStr(pt)
resolveOverloaded(alts, pt) match {
case alt :: Nil =>
@@ -982,14 +983,23 @@ class Typer extends Namer with Applications with Implicits {
case wtp: ExprType =>
adapt(tree.withType(wtp.resultType), pt)
case wtp: ImplicitMethodType =>
+ def implicitArgError(msg: => String): Tree = {
+ ctx.error(msg, tree.pos.endPos)
+ EmptyTree
+ }
val args = (wtp.paramNames, wtp.paramTypes).zipped map { (pname, formal) =>
- val arg = inferImplicit(formal, EmptyTree, tree.pos.endPos)
- if (arg.isEmpty)
- ctx.error(i"no implicit argument of type $formal found for parameter $pname of $methodStr", tree.pos.endPos)
- arg
+ def where = i"parameter $pname of $methodStr"
+ inferImplicit(formal, EmptyTree, tree.pos.endPos) match {
+ case SearchSuccess(arg) =>
+ arg
+ case ambi: AmbiguousImplicits =>
+ implicitArgError(s"ambiguous implicits: ${ambi.explanation} of $where")
+ case failure: SearchFailure =>
+ implicitArgError(i"no implicit argument of type $formal found for $where" + failure.postscript)
+ }
}
adapt(tpd.Apply(tree, args), pt)
- case wtp: MethodType =>
+ case wtp: MethodType if !pt.isInstanceOf[SingletonType] =>
if ((defn.isFunctionType(pt) || (pt eq AnyFunctionProto)) &&
!tree.symbol.isConstructor)
etaExpand(tree, wtp)
@@ -1026,10 +1036,10 @@ class Typer extends Namer with Applications with Implicits {
case _ =>
}
// try an implicit conversion
- val adapted = inferView(tree, pt)
- if (adapted ne EmptyTree) return adapted
- // if everything fails issue a type error
- err.typeMismatch(tree, pt)
+ inferView(tree, pt) match {
+ case SearchSuccess(adapted) => adapted
+ case failure: SearchFailure => err.typeMismatch(tree, pt, failure)
+ }
}
tree match {