Permalink
Browse files

Fix for Dynamic interaction with private methods.

Don't let inaccessible methods prevent calls to *Dynamic,
otherwise we are at the mercy of every "private" alteration
in every class we inherit.  Closes SI-5040.
  • Loading branch information...
paulp committed May 3, 2012
1 parent 8bc8b83 commit 780bed7fbb77d095cbc03eb0244f8b1f1e4cf88c
Showing with 23 additions and 10 deletions.
  1. +11 −10 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  2. +1 −0 test/files/run/t5040.check
  3. +11 −0 test/files/run/t5040.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
}
@@ -0,0 +1 @@
applyDynamic
@@ -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()
}

0 comments on commit 780bed7

Please sign in to comment.