summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala21
-rw-r--r--test/files/run/t5040.check1
-rw-r--r--test/files/run/t5040.scala11
3 files changed, 23 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6248d27727..5902e480a3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4247,6 +4247,8 @@ trait Typers extends Modes with Adaptations with Taggings {
* @return ...
*/
def typedSelect(qual: Tree, name: Name): Tree = {
+ def asDynamicCall = dyna.mkInvoke(context.tree, tree, qual, name) map (typed1(_, mode, pt))
+
val sym = tree.symbol orElse member(qual, name) orElse {
// symbol not found? --> try to convert implicitly to a type that does have the required
// member. Added `| PATTERNmode` to allow enrichment in patterns (so we can add e.g., an
@@ -4268,11 +4270,7 @@ trait Typers extends Modes with Adaptations with Taggings {
}
// try to expand according to Dynamic rules.
- dyna.mkInvoke(context.tree, tree, qual, name) match {
- case Some(invocation) =>
- return typed1(invocation, mode, pt)
- case _ =>
- }
+ asDynamicCall foreach (x => return x)
debuglog(
"qual = "+qual+":"+qual.tpe+
@@ -4311,7 +4309,8 @@ trait Typers extends Modes with Adaptations with Taggings {
if (err.kind != ErrorKinds.Access) {
context issue err
return setError(tree)
- } else (tree1, Some(err))
+ }
+ else (tree1, Some(err))
case SilentResultValue(treeAndPre) =>
(stabilize(treeAndPre._1, treeAndPre._2, mode, pt), None)
}
@@ -4341,10 +4340,12 @@ trait Typers extends Modes with Adaptations with Taggings {
val qual1 = adaptToMemberWithArgs(tree, qual, name, mode, false, false)
if (!qual1.isErrorTyped && (qual1 ne qual))
typed(Select(qual1, name) setPos tree.pos, mode, pt)
- else {
- issue(accessibleError.get)
- setError(tree)
- }
+ else
+ // before failing due to access, try a dynamic call.
+ asDynamicCall getOrElse {
+ issue(accessibleError.get)
+ setError(tree)
+ }
case _ =>
result
}
diff --git a/test/files/run/t5040.check b/test/files/run/t5040.check
new file mode 100644
index 0000000000..3f7b5908a9
--- /dev/null
+++ b/test/files/run/t5040.check
@@ -0,0 +1 @@
+applyDynamic
diff --git a/test/files/run/t5040.scala b/test/files/run/t5040.scala
new file mode 100644
index 0000000000..6cd2c22234
--- /dev/null
+++ b/test/files/run/t5040.scala
@@ -0,0 +1,11 @@
+abstract class Prova2 extends Dynamic {
+ def applyDynamic(m: String)(): Unit
+ private def privateMethod() = println("private method")
+}
+
+object Test extends App {
+ val prova= new Prova2 {
+ def applyDynamic(m: String)() = println("applyDynamic")
+ }
+ prova.privateMethod()
+}