diff options
author | Martin Odersky <odersky@gmail.com> | 2015-05-07 11:32:35 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-07 11:33:08 +0200 |
commit | 8f020bb6632d5d68e169f8caa7d9cbc1bc819d35 (patch) | |
tree | d849c43777a99fb6826057c207267b202daba228 /src/dotty/tools/backend/jvm | |
parent | a52ca600f2ad427276d1cdabd56133ffd0ed7610 (diff) | |
download | dotty-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.
Diffstat (limited to 'src/dotty/tools/backend/jvm')
-rw-r--r-- | src/dotty/tools/backend/jvm/DottyBackendInterface.scala | 20 |
1 files changed, 18 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, |