summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-06-21 10:09:50 +0000
committerMartin Odersky <odersky@gmail.com>2011-06-21 10:09:50 +0000
commitd8a4b0e8fc8ba1b4215567cf6860a8ff008b2ae4 (patch)
treee4f400713f6288f1dad4c33036106c294c4bea56 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent7d5b6fa1eefd098b4d08927b5a40497f4bb9c132 (diff)
downloadscala-d8a4b0e8fc8ba1b4215567cf6860a8ff008b2ae4.tar.gz
scala-d8a4b0e8fc8ba1b4215567cf6860a8ff008b2ae4.tar.bz2
scala-d8a4b0e8fc8ba1b4215567cf6860a8ff008b2ae4.zip
Fixes #4712. Review by moors.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index ed2a884101..7edb624b8e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2694,7 +2694,7 @@ trait Typers extends Modes {
(nme.ERROR, None)
} else {
names -= sym
- if(isJava) sym.cookJavaRawInfo() // #3429
+ if (isJava) sym.cookJavaRawInfo() // #3429
val annArg = tree2ConstArg(rhs, sym.tpe.resultType)
(sym.name, annArg)
}
@@ -3275,7 +3275,7 @@ trait Typers extends Modes {
}
}
- /** Try to apply function to arguments; if it does not work try to
+ /** Try to apply function to arguments; if it does not work, try to convert Java raw to existentials, or try to
* insert an implicit conversion.
*/
def tryTypedApply(fun: Tree, args: List[Tree]): Tree = {
@@ -3285,6 +3285,17 @@ trait Typers extends Modes {
t
case ex: TypeError =>
stopTimer(failedApplyNanos, start)
+
+ // If the problem is with raw types, copnvert to existentials and try again.
+ // See #4712 for a case where this situation arises,
+ if ((fun.symbol ne null) && fun.symbol.isJavaDefined) {
+ val newtpe = rawToExistential(fun.tpe)
+ if (fun.tpe ne newtpe) {
+ // println("late cooking: "+fun+":"+fun.tpe) // DEBUG
+ return tryTypedApply(fun setType newtpe, args)
+ }
+ }
+
def treesInResult(tree: Tree): List[Tree] = tree :: (tree match {
case Block(_, r) => treesInResult(r)
case Match(_, cases) => cases
@@ -3297,11 +3308,11 @@ trait Typers extends Modes {
})
def errorInResult(tree: Tree) = treesInResult(tree) exists (_.pos == ex.pos)
val retry = fun :: tree :: args exists errorInResult
- printTyping({
+ printTyping {
val funStr = ptTree(fun) + " and " + (args map ptTree mkString ", ")
if (retry) "second try: " + funStr
else "no second try: " + funStr + " because error not in result: " + ex.pos+"!="+tree.pos
- })
+ }
if (retry) {
val Select(qual, name) = fun
val args1 = tryTypedArgs(args, forArgMode(fun, mode), ex)