aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-05-07 11:32:35 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-07 11:33:08 +0200
commit8f020bb6632d5d68e169f8caa7d9cbc1bc819d35 (patch)
treed849c43777a99fb6826057c207267b202daba228
parenta52ca600f2ad427276d1cdabd56133ffd0ed7610 (diff)
downloaddotty-8f020bb6632d5d68e169f8caa7d9cbc1bc819d35.tar.gz
dotty-8f020bb6632d5d68e169f8caa7d9cbc1bc819d35.tar.bz2
dotty-8f020bb6632d5d68e169f8caa7d9cbc1bc819d35.zip
Fix #536 - only load member classes of classes that are currently compiled.
It seems wasteful to load the member classes even of classes that are not currently compiled. It also makes us vulnerable to any misinterpretation of Java file formats. In th particular case of #536, we parsed a class an anonymous Collection$1 which was referring to the type parameter of its enclosing class, but was not diagnosed as an inner class of the enclosing class.
-rw-r--r--src/dotty/tools/backend/jvm/DottyBackendInterface.scala20
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala2
-rw-r--r--tests/pos/i536.scala3
3 files changed, 23 insertions, 2 deletions
diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
index dc6752460..7a510857d 100644
--- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
+++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
@@ -678,8 +678,24 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
// members
def primaryConstructor: Symbol = toDenot(sym).primaryConstructor
- def nestedClasses: List[Symbol] = memberClasses //exitingPhase(currentRun.lambdaliftPhase)(sym.memberClasses)
- def memberClasses: List[Symbol] = toDenot(sym).info.memberClasses.map(_.symbol).toList
+
+ /** For currently compiled classes: All locally defined classes including local classes.
+ * The empty list for classes that are not currently compiled.
+ */
+ def nestedClasses: List[Symbol] = localClasses(ctx.flattenPhase)
+
+ /** For currently compiled classes: All classes that are declared as members of this class
+ * (but not inherited ones). The empty list for classes that are not currently compiled.
+ */
+ def memberClasses: List[Symbol] = localClasses(ctx.lambdaLiftPhase)
+
+ private def localClasses(phase: Phase) =
+ if (sym.isDefinedInCurrentRun)
+ ctx.atPhase(phase) { implicit ctx =>
+ toDenot(sym).info.decls.filter(_.isClass).toList
+ }
+ else Nil
+
def annotations: List[Annotation] = Nil
def companionModuleMembers: List[Symbol] = {
// phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes,
diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala
index 406a3457a..e0496185e 100644
--- a/src/dotty/tools/dotc/core/Phases.scala
+++ b/src/dotty/tools/dotc/core/Phases.scala
@@ -235,6 +235,7 @@ object Phases {
private val extensionMethodsCache = new PhaseCache(classOf[ExtensionMethods])
private val erasureCache = new PhaseCache(classOf[Erasure])
private val patmatCache = new PhaseCache(classOf[PatternMatcher])
+ private val lambdaLiftCache = new PhaseCache(classOf[LambdaLift])
private val flattenCache = new PhaseCache(classOf[Flatten])
private val explicitOuterCache = new PhaseCache(classOf[ExplicitOuter])
private val gettersCache = new PhaseCache(classOf[Getters])
@@ -245,6 +246,7 @@ object Phases {
def extensionMethodsPhase = extensionMethodsCache.phase
def erasurePhase = erasureCache.phase
def patmatPhase = patmatCache.phase
+ def lambdaLiftPhase = lambdaLiftCache.phase
def flattenPhase = flattenCache.phase
def explicitOuterPhase = explicitOuterCache.phase
def gettersPhase = gettersCache.phase
diff --git a/tests/pos/i536.scala b/tests/pos/i536.scala
new file mode 100644
index 000000000..db9fb9b38
--- /dev/null
+++ b/tests/pos/i536.scala
@@ -0,0 +1,3 @@
+object Max {
+ java.util.Collections.max(null)
+}