Skip to content

Commit

Permalink
Fixes #4193 http://is.gd/i1esyC discussed on http://is.gd/JSnbcW : Ma…
Browse files Browse the repository at this point in the history
…kes compiler smarter about picking overloaded methods
  • Loading branch information
chirino committed Feb 8, 2011
1 parent caad759 commit bc0ff4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Expand Up @@ -121,6 +121,7 @@ trait Contexts { self: Analyzer =>
var reportGeneralErrors = false
var diagnostic: List[String] = Nil // these messages are printed when issuing an error
var implicitsEnabled = false
var isAsSpecificDropsByName = false
var checking = false
var retyping = false

Expand Down
29 changes: 27 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Infer.scala
Expand Up @@ -871,7 +871,12 @@ trait Infer {
if (isVarArgsList(params) && isVarArgsList(ftpe2.params))
argtpes = argtpes map (argtpe =>
if (isRepeatedParamType(argtpe)) argtpe.typeArgs.head else argtpe)
isApplicable(List(), ftpe2, argtpes, WildcardType)
val rc = if( context.isAsSpecificDropsByName ) {
isApplicable(List(), ftpe2, formalTypes(argtpes, argtpes.length), WildcardType)
} else {
isApplicable(List(), ftpe2, argtpes, WildcardType)
}
rc
case PolyType(tparams, NullaryMethodType(res)) =>
isAsSpecific(PolyType(tparams, res), ftpe2)
case PolyType(tparams, mt: MethodType) if mt.isImplicit =>
Expand Down Expand Up @@ -1634,7 +1639,7 @@ trait Infer {
*
* @param infer ...
*/
def tryTwice(infer: => Unit) {
def tryTwice(infer: => Unit) = tryTwiceRelaxingByName {
if (context.implicitsEnabled) {
val reportGeneralErrors = context.reportGeneralErrors
context.reportGeneralErrors = false
Expand All @@ -1652,6 +1657,26 @@ trait Infer {
else infer
}

def tryTwiceRelaxingByName(infer: => Unit) {
val originalErrors = context.reportAmbiguousErrors
val original = context.isAsSpecificDropsByName
context.reportAmbiguousErrors = false
try {
context.isAsSpecificDropsByName = false
infer
} catch {
case ex: CyclicReference => throw ex
case ex: TypeError =>
context.reportAmbiguousErrors = originalErrors
context.isAsSpecificDropsByName = true
infer
} finally {
context.isAsSpecificDropsByName = original
context.reportAmbiguousErrors = originalErrors
}
}


/** Assign <code>tree</code> the type of unique polymorphic alternative
* with <code>nparams</code> as the number of type parameters, if it exists.
* If several or none such polymorphic alternatives exist, error.
Expand Down

0 comments on commit bc0ff4b

Please sign in to comment.