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