@@ -35,6 +35,7 @@ import ExplicitOuter.*
35
35
import core .Mode
36
36
import util .Property
37
37
import reporting .*
38
+ import scala .annotation .tailrec
38
39
39
40
class Erasure extends Phase with DenotTransformer {
40
41
@@ -755,7 +756,8 @@ object Erasure {
755
756
(ctx.owner.enclosingPackageClass eq boundary)
756
757
}
757
758
758
- def recur (qual : Tree ): Tree = {
759
+ @ tailrec
760
+ def recur (qual : Tree ): Tree =
759
761
val qualIsPrimitive = qual.tpe.widen.isPrimitiveValueType
760
762
val symIsPrimitive = sym.owner.isPrimitiveValueClass
761
763
@@ -764,33 +766,34 @@ object Erasure {
764
766
inContext(preErasureCtx):
765
767
tree.qualifier.typeOpt.widen.finalResultType)
766
768
767
- if ( qualIsPrimitive && ! symIsPrimitive || qual.tpe.widenDealias.isErasedValueType)
769
+ if qualIsPrimitive && ! symIsPrimitive || qual.tpe.widenDealias.isErasedValueType then
768
770
recur(box(qual))
769
- else if ( ! qualIsPrimitive && symIsPrimitive)
771
+ else if ! qualIsPrimitive && symIsPrimitive then
770
772
recur(unbox(qual, sym.owner.typeRef))
771
- else if ( sym.owner eq defn.ArrayClass )
773
+ else if sym.owner eq defn.ArrayClass then
772
774
selectArrayMember(qual, originalQual)
773
- else {
774
- val qual1 = adaptIfSuper(qual)
775
- if (qual1.tpe.derivesFrom(sym.owner) || qual1.isInstanceOf [Super ])
776
- select(qual1, sym)
777
- else
778
- val castTarget = // Avoid inaccessible cast targets, see i8661
779
- if isJvmAccessible(sym.owner) && sym.owner.isType
780
- then
781
- sym.owner.typeRef
782
- else
783
- // If the owner is inaccessible, try going through the qualifier,
784
- // but be careful to not go in an infinite loop in case that doesn't
785
- // work either.
786
- val tp = originalQual
787
- if tp =:= qual1.tpe.widen then
788
- return errorTree(qual1,
789
- em " Unable to emit reference to ${sym.showLocated}, ${sym.owner} is not accessible in ${ctx.owner.enclosingClass}" )
790
- tp
791
- recur(cast(qual1, castTarget))
792
- }
793
- }
775
+ else
776
+ adaptIfSuper(qual) match
777
+ case qual1 : Super =>
778
+ select(qual1, sym)
779
+ case qual1 if ! isJvmAccessible(qual1.tpe.typeSymbol)
780
+ || ! qual1.tpe.derivesFrom(sym.owner) =>
781
+ val castTarget = // Avoid inaccessible cast targets, see i8661
782
+ if isJvmAccessible(sym.owner) && sym.owner.isType then
783
+ sym.owner.typeRef
784
+ else
785
+ // If the owner is inaccessible, try going through the qualifier,
786
+ // but be careful to not go in an infinite loop in case that doesn't
787
+ // work either.
788
+ val tp = originalQual
789
+ if tp =:= qual1.tpe.widen then
790
+ return errorTree(qual1,
791
+ em " Unable to emit reference to ${sym.showLocated}, ${sym.owner} is not accessible in ${ctx.owner.enclosingClass}" )
792
+ tp
793
+ recur(cast(qual1, castTarget))
794
+ case qual1 =>
795
+ select(qual1, sym)
796
+ end recur
794
797
795
798
checkNotErased(recur(qual1))
796
799
}
0 commit comments