From 9ecd3d14510a9eafe8c8275b0027f6ee8f0b3fea Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 15 Mar 2018 15:44:51 +0100 Subject: [PATCH] Do not pickle empty packages Unpickling them may lead to stub symbol errors --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 6 +++++- .../src/dotty/tools/dotc/transform/FirstTransform.scala | 4 ---- compiler/test/dotty/tools/dotc/FromTastyTests.scala | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 89dc8fc4756e..6aecb1791903 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -633,7 +633,11 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => /** The tree containing only the top-level classes and objects matching either `cls` or its companion object */ def sliceTopLevel(tree: Tree, cls: ClassSymbol)(implicit ctx: Context): List[Tree] = tree match { case PackageDef(pid, stats) => - cpy.PackageDef(tree)(pid, stats.flatMap(sliceTopLevel(_, cls))) :: Nil + val slicedStats = stats.flatMap(sliceTopLevel(_, cls)) + if (!slicedStats.isEmpty) + cpy.PackageDef(tree)(pid, slicedStats) :: Nil + else + Nil case tdef: TypeDef => val sym = tdef.symbol assert(sym.isClass) diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index 3240300d8f52..f988e519862d 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -116,10 +116,6 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => cpy.Template(impl)(self = EmptyValDef) } - /** Eliminate empty package definitions that may have been stored in the TASTY trees */ - override def transformPackageDef(tree: PackageDef)(implicit ctx: Context): Tree = - if (tree.stats.isEmpty) EmptyTree else tree - override def transformDefDef(ddef: DefDef)(implicit ctx: Context) = { if (ddef.symbol.hasAnnotation(defn.NativeAnnot)) { ddef.symbol.resetFlag(Deferred) diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 9393160a78b9..bcc5aefbfe16 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -47,7 +47,6 @@ class FromTastyTests extends ParallelTesting { "hklub0.scala", // Missing position - "i3000.scala", "t1203a.scala", "t2260.scala", "t4579.scala",