@@ -67,16 +67,22 @@ object FromTasty extends Driver {
67
67
override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] =
68
68
units.flatMap(readTASTY)
69
69
70
- def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): List [CompilationUnit ] = unit match {
70
+ def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): Option [CompilationUnit ] = unit match {
71
71
case unit : TASTYCompilationUnit =>
72
72
assert(ctx.settings.YretainTrees .value)
73
73
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
+ }
78
79
}
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))
80
86
}
81
87
82
88
private def tree (className : TypeName )(implicit ctx : Context ): Option [(ClassDenotation , tpd.Tree )] = {
0 commit comments