Skip to content

Commit

Permalink
SI-6551: don't insert apply call in polymorphic expression.
Browse files Browse the repository at this point in the history
Don't rewrite an explicit apply method to dynamic polytypes.
  • Loading branch information
namin committed Nov 16, 2012
1 parent 73d9ae5 commit 74ca558
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -1100,6 +1100,10 @@ trait Typers extends Modes with Adaptations with Tags {
instantiateToMethodType(mt)

case _ =>
def shouldInsertApply(tree: Tree) = inAllModes(mode, EXPRmode | FUNmode) && (tree.tpe match {
case _: MethodType | _: OverloadedType | _: PolyType => false
case _ => applyPossible
})
def applyPossible = {
def applyMeth = member(adaptToName(tree, nme.apply), nme.apply)
dyna.acceptsApplyDynamic(tree.tpe) || (
Expand All @@ -1117,10 +1121,7 @@ trait Typers extends Modes with Adaptations with Tags {
macroExpand(this, tree, mode, pt)
else if ((mode & (PATTERNmode | FUNmode)) == (PATTERNmode | FUNmode))
adaptConstrPattern()
else if (inAllModes(mode, EXPRmode | FUNmode) &&
!tree.tpe.isInstanceOf[MethodType] &&
!tree.tpe.isInstanceOf[OverloadedType] &&
applyPossible)
else if (shouldInsertApply(tree))
insertApply()
else if (!context.undetparams.isEmpty && !inPolyMode(mode)) { // (9)
assert(!inHKMode(mode), modeString(mode)) //@M
Expand Down
13 changes: 13 additions & 0 deletions test/files/pos/t6551.scala
@@ -0,0 +1,13 @@
import language.dynamics

object Test {
def main(args: Array[String]) {
class Lenser[T] extends Dynamic {
def selectDynamic(propName: String) = ???
}

def lens[T] = new Lenser[T]

val qq = lens[String]
}
}

0 comments on commit 74ca558

Please sign in to comment.