Skip to content

Commit 74ca558

Browse files
committed
SI-6551: don't insert apply call in polymorphic expression.
Don't rewrite an explicit apply method to dynamic polytypes.
1 parent 73d9ae5 commit 74ca558

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ trait Typers extends Modes with Adaptations with Tags {
11001100
instantiateToMethodType(mt)
11011101

11021102
case _ =>
1103+
def shouldInsertApply(tree: Tree) = inAllModes(mode, EXPRmode | FUNmode) && (tree.tpe match {
1104+
case _: MethodType | _: OverloadedType | _: PolyType => false
1105+
case _ => applyPossible
1106+
})
11031107
def applyPossible = {
11041108
def applyMeth = member(adaptToName(tree, nme.apply), nme.apply)
11051109
dyna.acceptsApplyDynamic(tree.tpe) || (
@@ -1117,10 +1121,7 @@ trait Typers extends Modes with Adaptations with Tags {
11171121
macroExpand(this, tree, mode, pt)
11181122
else if ((mode & (PATTERNmode | FUNmode)) == (PATTERNmode | FUNmode))
11191123
adaptConstrPattern()
1120-
else if (inAllModes(mode, EXPRmode | FUNmode) &&
1121-
!tree.tpe.isInstanceOf[MethodType] &&
1122-
!tree.tpe.isInstanceOf[OverloadedType] &&
1123-
applyPossible)
1124+
else if (shouldInsertApply(tree))
11241125
insertApply()
11251126
else if (!context.undetparams.isEmpty && !inPolyMode(mode)) { // (9)
11261127
assert(!inHKMode(mode), modeString(mode)) //@M

test/files/pos/t6551.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.dynamics
2+
3+
object Test {
4+
def main(args: Array[String]) {
5+
class Lenser[T] extends Dynamic {
6+
def selectDynamic(propName: String) = ???
7+
}
8+
9+
def lens[T] = new Lenser[T]
10+
11+
val qq = lens[String]
12+
}
13+
}

0 commit comments

Comments
 (0)