File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg/java-trait-access Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -688,12 +688,16 @@ object Erasure {
688
688
def recur (qual : Tree ): Tree = {
689
689
val qualIsPrimitive = qual.tpe.widen.isPrimitiveValueType
690
690
val symIsPrimitive = sym.owner.isPrimitiveValueClass
691
+
692
+ def originalQual : Type =
693
+ erasure(tree.qualifier.typeOpt.widen.finalResultType)
694
+
691
695
if (qualIsPrimitive && ! symIsPrimitive || qual.tpe.widenDealias.isErasedValueType)
692
696
recur(box(qual))
693
697
else if (! qualIsPrimitive && symIsPrimitive)
694
698
recur(unbox(qual, sym.owner.typeRef))
695
699
else if (sym.owner eq defn.ArrayClass )
696
- selectArrayMember(qual, erasure(tree.qualifier.typeOpt.widen.finalResultType) )
700
+ selectArrayMember(qual, originalQual )
697
701
else {
698
702
val qual1 = adaptIfSuper(qual)
699
703
if (qual1.tpe.derivesFrom(sym.owner) || qual1.isInstanceOf [Super ])
@@ -707,7 +711,7 @@ object Erasure {
707
711
// If the owner is inaccessible, try going through the qualifier,
708
712
// but be careful to not go in an infinite loop in case that doesn't
709
713
// work either.
710
- val tp = erasure(tree.qualifier.typeOpt.widen)
714
+ val tp = originalQual
711
715
if tp =:= qual1.tpe.widen then
712
716
return errorTree(qual1,
713
717
ex " Unable to emit reference to ${sym.showLocated}, ${sym.owner} is not accessible in ${ctx.owner.enclosingClass}" )
Original file line number Diff line number Diff line change @@ -10,4 +10,9 @@ object Test {
10
10
val b : pkg.B = c
11
11
b.foo() // error: Unable to emit reference to method foo in class A, class A is not accessible in object Test
12
12
}
13
+
14
+ val c2 = new pkg.C
15
+ c2.foo() // OK
16
+ val b2 : pkg.B = c2
17
+ b2.foo() // error: Unable to emit reference to method foo in class A, class A is not accessible in object Test
13
18
}
You can’t perform that action at this time.
0 commit comments