Skip to content

Commit

Permalink
Fix for Dynamic interaction with private methods.
Browse files Browse the repository at this point in the history
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 4, 2012
1 parent 8bc8b83 commit 780bed7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -4247,6 +4247,8 @@ trait Typers extends Modes with Adaptations with Taggings {
* @return ... * @return ...
*/ */
def typedSelect(qual: Tree, name: Name): Tree = { 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 { val sym = tree.symbol orElse member(qual, name) orElse {
// symbol not found? --> try to convert implicitly to a type that does have the required // 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 // member. Added `| PATTERNmode` to allow enrichment in patterns (so we can add e.g., an
Expand All @@ -4268,11 +4270,7 @@ trait Typers extends Modes with Adaptations with Taggings {
} }


// try to expand according to Dynamic rules. // try to expand according to Dynamic rules.
dyna.mkInvoke(context.tree, tree, qual, name) match { asDynamicCall foreach (x => return x)
case Some(invocation) =>
return typed1(invocation, mode, pt)
case _ =>
}


debuglog( debuglog(
"qual = "+qual+":"+qual.tpe+ "qual = "+qual+":"+qual.tpe+
Expand Down Expand Up @@ -4311,7 +4309,8 @@ trait Typers extends Modes with Adaptations with Taggings {
if (err.kind != ErrorKinds.Access) { if (err.kind != ErrorKinds.Access) {
context issue err context issue err
return setError(tree) return setError(tree)
} else (tree1, Some(err)) }
else (tree1, Some(err))
case SilentResultValue(treeAndPre) => case SilentResultValue(treeAndPre) =>
(stabilize(treeAndPre._1, treeAndPre._2, mode, pt), None) (stabilize(treeAndPre._1, treeAndPre._2, mode, pt), None)
} }
Expand Down Expand Up @@ -4341,10 +4340,12 @@ trait Typers extends Modes with Adaptations with Taggings {
val qual1 = adaptToMemberWithArgs(tree, qual, name, mode, false, false) val qual1 = adaptToMemberWithArgs(tree, qual, name, mode, false, false)
if (!qual1.isErrorTyped && (qual1 ne qual)) if (!qual1.isErrorTyped && (qual1 ne qual))
typed(Select(qual1, name) setPos tree.pos, mode, pt) typed(Select(qual1, name) setPos tree.pos, mode, pt)
else { else
issue(accessibleError.get) // before failing due to access, try a dynamic call.
setError(tree) asDynamicCall getOrElse {
} issue(accessibleError.get)
setError(tree)
}
case _ => case _ =>
result result
} }
Expand Down
1 change: 1 addition & 0 deletions test/files/run/t5040.check
@@ -0,0 +1 @@
applyDynamic
11 changes: 11 additions & 0 deletions 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()
}

0 comments on commit 780bed7

Please sign in to comment.