@@ -67,16 +67,22 @@ object FromTasty extends Driver {
6767 override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] =
6868 units.flatMap(readTASTY)
6969
70- def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): List [CompilationUnit ] = unit match {
70+ def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): Option [CompilationUnit ] = unit match {
7171 case unit : TASTYCompilationUnit =>
7272 assert(ctx.settings.YretainTrees .value)
7373 val className = unit.className.toTypeName
74- val compilationUnits = List (tree(className), tree(className.moduleClassName)).flatMap {
75- case Some ((clsd, unpickled)) if ! unpickled.isEmpty =>
76- List (CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true ))
77- case _ => Nil
74+ def compilationUnit (className : TypeName ): Option [CompilationUnit ] = {
75+ tree(className).flatMap { case (clsd, unpickled) =>
76+ if (unpickled.isEmpty) None
77+ else Some (CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true ))
78+ }
7879 }
79- compilationUnits
80+ // The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
81+ // We first try to load the class and fallback to loading the object if the class doesn't exist.
82+ // Note that if both the class and the object are present, then loading the class will also load
83+ // the object, this is why we use orElse here, otherwise we could load the object twice and
84+ // create ambiguities!
85+ compilationUnit(className).orElse(compilationUnit(className.moduleClassName))
8086 }
8187
8288 private def tree (className : TypeName )(implicit ctx : Context ): Option [(ClassDenotation , tpd.Tree )] = {
0 commit comments