Skip to content
Permalink
Browse files

Closes SI-5735, this could also potentially fix a SO problem that @ad…

…riaanm was experiencing in IDE but could not reproduce it.
  • Loading branch information
hubertp committed May 21, 2012
1 parent ef77088 commit bbfbd6694d564552a6a8d903dc5d6e34f5976c2b
@@ -711,12 +711,14 @@ trait ContextErrors {
issueAmbiguousTypeError(pre, best, firstCompeting, AmbiguousTypeError(tree, pos, msg))
}

def NoBestExprAlternativeError(tree: Tree, pt: Type) =
def NoBestExprAlternativeError(tree: Tree, pt: Type) = {
issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(tree.symbol.tpe, pt, isPossiblyMissingArgs(tree.symbol.tpe, pt))))
if (implicitly[Context].reportErrors) setError(tree)
}

def AmbiguousExprAlternativeError(tree: Tree, pre: Type, best: Symbol, firstCompeting: Symbol, pt: Type) = {
val (pos, msg) = ambiguousErrorMsgPos(tree.pos, pre, best, firstCompeting, "expected type " + pt)
setError(tree)
if (implicitly[Context].ambiguousErrors) setError(tree)
issueAmbiguousTypeError(pre, best, firstCompeting, AmbiguousTypeError(tree, pos, msg))
}

@@ -1450,7 +1450,9 @@ trait Infer {
def inferExprAlternative(tree: Tree, pt: Type) = tree.tpe match {
case OverloadedType(pre, alts) => tryTwice {
val alts0 = alts filter (alt => isWeaklyCompatible(pre.memberType(alt), pt))
val secondTry = alts0.isEmpty
// secondTry is not a sufficient condition to decide whether that was our final attempt.
// This is because it doesn't take into account tryTwice implicits search option.
val secondTry = alts0.isEmpty
val alts1 = if (secondTry) alts else alts0

//println("trying "+alts1+(alts1 map (_.tpe))+(alts1 map (_.locationString))+" for "+pt)
@@ -1481,7 +1483,7 @@ trait Infer {
// todo: missing test case
NoBestExprAlternativeError(tree, pt)
} else if (!competing.isEmpty) {
if (secondTry) { NoBestExprAlternativeError(tree, pt); setError(tree) }
if (secondTry) NoBestExprAlternativeError(tree, pt)
else if (!pt.isErroneous) AmbiguousExprAlternativeError(tree, pre, best, competing.head, pt)
} else {
// val applicable = alts1 filter (alt =>
@@ -0,0 +1,6 @@
t5735.scala:6: error: type mismatch;
found : (x: Int)Int <and> => String
required: Int
val z: Int = a
^
one error found
@@ -0,0 +1,7 @@
abstract class Base {
def a: String = "one"
}
class Clazz extends Base {
def a(x: Int): Int = 2
val z: Int = a
}

0 comments on commit bbfbd66

Please sign in to comment.
You can’t perform that action at this time.