Skip to content

Commit 2e2fcc0

Browse files
committed
Fix #1470: Fix dynamic selection in presence of inaccessible member of the sam name
1 parent 772feca commit 2e2fcc0

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ trait TypeAssigner {
203203
*/
204204
def selectionType(site: Type, name: Name, pos: Position)(implicit ctx: Context): Type = {
205205
val mbr = site.member(name)
206-
if (reallyExists(mbr)) site.select(name, mbr)
207-
else if (site.derivesFrom(defn.DynamicClass) && !Dynamic.isDynamicMethod(name)) {
206+
lazy val canBeDynamicMethod = site.derivesFrom(defn.DynamicClass) && !Dynamic.isDynamicMethod(name)
207+
if (reallyExists(mbr) && (mbr.accessibleFrom(site).exists || !canBeDynamicMethod)) site.select(name, mbr)
208+
else if (canBeDynamicMethod) {
208209
TryDynamicCallType
209210
} else {
210211
if (!site.isErroneous) {
File renamed without changes.
File renamed without changes.

tests/pending/run/t5040.scala renamed to tests/run/t5040.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import scala.language.dynamics // originaly used the flag -language:dynamics in t5040.flags, .flags are currently ignored
12
abstract class Prova2 extends Dynamic {
23
def applyDynamic(m: String)(): Unit
34
private def privateMethod() = println("private method")

0 commit comments

Comments
 (0)