diff options
author | amin <nada.amin@epfl.ch> | 2012-09-17 01:12:13 +0200 |
---|---|---|
committer | amin <nada.amin@epfl.ch> | 2012-09-17 01:38:33 +0200 |
commit | dbe7ef94dd5ea031b1d9e65a6843ff2ff5b28fe5 (patch) | |
tree | b09f683a2d11c7a7d1961b8bb83cc1446b47814e /src | |
parent | 112009844bb184acfeaef0435e142a3cfd5a895b (diff) | |
download | scala-dbe7ef94dd5ea031b1d9e65a6843ff2ff5b28fe5.tar.gz scala-dbe7ef94dd5ea031b1d9e65a6843ff2ff5b28fe5.tar.bz2 scala-dbe7ef94dd5ea031b1d9e65a6843ff2ff5b28fe5.zip |
Fixed SI-6353: applyDynamic with sugared applications
- Accept sugared applications such as x(1) if x implements Dynamic,
so x(1) gets re-written to x.apply(1).
- When picking a dynamic rewrite for x.apply(1), favor applyDynamic
instead of the default selectDynamic.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5200aae8d1..58732ef575 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1107,10 +1107,12 @@ trait Typers extends Modes with Adaptations with Tags { case _ => def applyPossible = { def applyMeth = member(adaptToName(tree, nme.apply), nme.apply) - if ((mode & TAPPmode) != 0) - tree.tpe.typeParams.isEmpty && applyMeth.filter(!_.tpe.typeParams.isEmpty) != NoSymbol - else - applyMeth.filter(_.tpe.paramSectionCount > 0) != NoSymbol + dyna.acceptsApplyDynamic(tree.tpe) || ( + if ((mode & TAPPmode) != 0) + tree.tpe.typeParams.isEmpty && applyMeth.filter(!_.tpe.typeParams.isEmpty) != NoSymbol + else + applyMeth.filter(_.tpe.paramSectionCount > 0) != NoSymbol + ) } if (tree.isType) adaptType() @@ -3842,11 +3844,15 @@ trait Typers extends Modes with Adaptations with Tags { } @inline def hasNamedArg(as: List[Tree]) = as.collectFirst{case AssignOrNamedArg(lhs, rhs) =>}.nonEmpty + def desugaredApply = tree match { + case Select(`qual`, nme.apply) => true + case _ => false + } // note: context.tree includes at most one Apply node // thus, we can't use it to detect we're going to receive named args in expressions such as: // qual.sel(a)(a2, arg2 = "a2") val oper = outer match { - case Apply(`tree`, as) => + case Apply(q, as) if q == tree || desugaredApply => val oper = if (hasNamedArg(as)) nme.applyDynamicNamed else nme.applyDynamic |