Skip to content

Commit a05eda7

Browse files
committed
Avoid loading compilation units twice
For some class name foo.Foo we need to try to load the tasty from the its class. If the class is not definded, we try load it from the obeject. Previously, if both the class and the object extists we were loading the compilation unit twice. Which would duplicate symbols and then fail with duplicated symbol definitions.
1 parent 03d660a commit a05eda7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/FromTasty.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ object FromTasty extends Driver {
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+
compilationUnit(className).orElse(compilationUnit(className.moduleClassName)).toList
8081
}
8182

8283
private def tree(className: TypeName)(implicit ctx: Context): Option[(ClassDenotation, tpd.Tree)] = {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package foo
2+
3+
case object Foo
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package foo
2+
3+
class Foo
4+
object Foo

0 commit comments

Comments
 (0)