Skip to content

Commit aeafe2d

Browse files
committed
Erasure#typedSelect: Use correct type as cast target
The missing `.finalResultType` meant we could end up trying to cast to a MethodType.
1 parent 9d12f01 commit aeafe2d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,16 @@ object Erasure {
688688
def recur(qual: Tree): Tree = {
689689
val qualIsPrimitive = qual.tpe.widen.isPrimitiveValueType
690690
val symIsPrimitive = sym.owner.isPrimitiveValueClass
691+
692+
def originalQual: Type =
693+
erasure(tree.qualifier.typeOpt.widen.finalResultType)
694+
691695
if (qualIsPrimitive && !symIsPrimitive || qual.tpe.widenDealias.isErasedValueType)
692696
recur(box(qual))
693697
else if (!qualIsPrimitive && symIsPrimitive)
694698
recur(unbox(qual, sym.owner.typeRef))
695699
else if (sym.owner eq defn.ArrayClass)
696-
selectArrayMember(qual, erasure(tree.qualifier.typeOpt.widen.finalResultType))
700+
selectArrayMember(qual, originalQual)
697701
else {
698702
val qual1 = adaptIfSuper(qual)
699703
if (qual1.tpe.derivesFrom(sym.owner) || qual1.isInstanceOf[Super])
@@ -707,7 +711,7 @@ object Erasure {
707711
// If the owner is inaccessible, try going through the qualifier,
708712
// but be careful to not go in an infinite loop in case that doesn't
709713
// work either.
710-
val tp = erasure(tree.qualifier.typeOpt.widen)
714+
val tp = originalQual
711715
if tp =:= qual1.tpe.widen then
712716
return errorTree(qual1,
713717
ex"Unable to emit reference to ${sym.showLocated}, ${sym.owner} is not accessible in ${ctx.owner.enclosingClass}")

tests/neg/java-trait-access/B.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ object Test {
1010
val b: pkg.B = c
1111
b.foo() // error: Unable to emit reference to method foo in class A, class A is not accessible in object Test
1212
}
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
1318
}

0 commit comments

Comments
 (0)