Permalink
Browse files

SI-7974 Avoid calling nonPrivateMember after erasure

One example were this would lead to subtle bugs otherwise is
Symbol_apply, where after erasure an overloaded symbol containing
Symbol#apply and UniquenessCache#apply is returned.

    // findMember considered harmful after erasure; e.g.
    //
    // scala> exitingErasure(Symbol_apply).isOverloaded
    // res27: Boolean = true
  • Loading branch information...
1 parent b2bf66a commit 5e1e472fa10145606fbe3ff2966c35e2842d3894 @soc soc committed Nov 19, 2013
@@ -1207,15 +1207,21 @@ trait Definitions extends api.StandardDefinitions {
}
def getMemberMethod(owner: Symbol, name: Name): TermSymbol = {
getMember(owner, name.toTermName) match {
- // todo. member symbol becomes a term symbol in cleanup. is this a bug?
- // case x: MethodSymbol => x
case x: TermSymbol => x
case _ => fatalMissingSymbol(owner, name, "method")
}
}
+ private lazy val erasurePhase = findPhaseWithName("erasure")
def getMemberIfDefined(owner: Symbol, name: Name): Symbol =
- owner.info.nonPrivateMember(name)
+ // findMember considered harmful after erasure; e.g.
+ //
+ // scala> exitingErasure(Symbol_apply).isOverloaded
+ // res27: Boolean = true
+ //
+ enteringPhaseNotLaterThan(erasurePhase )(
+ owner.info.nonPrivateMember(name)
+ )
/** Using getDecl rather than getMember may avoid issues with
* OverloadedTypes turning up when you don't want them, if you
@@ -244,6 +244,18 @@ abstract class SymbolTable extends macros.Universe
finally popPhase(saved)
}
+ final def findPhaseWithName(phaseName: String): Phase = {
+ var ph = phase
+ while (ph != NoPhase && ph.name != phaseName) {
+ ph = ph.prev
+ }
+ if (ph eq NoPhase) phase else ph
+ }
+ final def enteringPhaseWithName[T](phaseName: String)(body: => T): T = {
+ val phase = findPhaseWithName(phaseName)
+ enteringPhase(phase)(body)
+ }
+
def slowButSafeEnteringPhase[T](ph: Phase)(op: => T): T = {
if (isCompilerUniverse) enteringPhase(ph)(op)
else op
@@ -41,7 +41,8 @@ trait TraceSymbolActivity {
}
}
- private def signature(id: Int) = runBeforeErasure(allSymbols(id).defString)
+ private lazy val erasurePhase = findPhaseWithName("erasure")
+ private def signature(id: Int) = enteringPhase(erasurePhase)(allSymbols(id).defString)
private def dashes(s: Any): String = ("" + s) map (_ => '-')
private def show(s1: Any, ss: Any*) {
@@ -87,14 +88,6 @@ trait TraceSymbolActivity {
private def showFreq[T, U](xs: Traversable[T])(groupFn: T => U, showFn: U => String) = {
showMapFreq(xs.toList groupBy groupFn)(showFn)
}
- private lazy val findErasurePhase: Phase = {
- var ph = phase
- while (ph != NoPhase && ph.name != "erasure") {
- ph = ph.prev
- }
- if (ph eq NoPhase) phase else ph
- }
- private def runBeforeErasure[T](body: => T): T = enteringPhase(findErasurePhase)(body)
def showAllSymbols() {
if (!enabled) return
@@ -425,6 +425,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.languageFeatureModule
definitions.metaAnnotations
definitions.AnnotationDefaultAttr
+ // inaccessible: definitions.erasurePhase
definitions.isPhantomClass
definitions.syntheticCoreClasses
definitions.syntheticCoreMethods

0 comments on commit 5e1e472

Please sign in to comment.