Skip to content

Commit 83a60b6

Browse files
committed
Simplify the pickled tree after unpickler
1 parent cbd747d commit 83a60b6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Phases._
1212
import Symbols._
1313
import Flags.Module
1414
import reporting.{ThrowingReporter, Profile}
15-
import typer.Nullables
1615
import collection.mutable
1716
import scala.concurrent.{Future, Await, ExecutionContext}
1817
import scala.concurrent.duration.Duration
@@ -50,7 +49,7 @@ class Pickler extends Phase {
5049
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
5150
private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler]
5251

53-
private val typeSimplifier = new TypeSimplifyTransformer
52+
private val typeSimplifier = new TypeSimplifier
5453

5554
/** Drop any elements of this list that are linked module classes of other elements in the list */
5655
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(using Context): List[ClassSymbol] = {
@@ -69,7 +68,7 @@ class Pickler extends Phase {
6968
do
7069
val pickler = new TastyPickler(cls)
7170
if ctx.settings.YtestPickler.value then
72-
beforePickling(cls) = typeSimplifier.transform(tree).show
71+
beforePickling(cls) = tree.show
7372
picklers(cls) = pickler
7473
val treePkl = new TreePickler(pickler)
7574
treePkl.pickle(tree :: Nil)
@@ -157,10 +156,10 @@ class Pickler extends Phase {
157156

158157
// Overwrite types of If, Match, and Try nodes with simplified types
159158
// to avoid inconsistencies in unsafe nulls
160-
class TypeSimplifyTransformer extends TreeMapWithPreciseStatContexts:
159+
class TypeSimplifier extends TreeMapWithPreciseStatContexts:
161160
override def transform(tree: Tree)(using Context): Tree =
162161
try tree match
163-
case _: If | _: Match | _: Try if Nullables.unsafeNullsEnabled =>
162+
case _: If | _: Match | _: Try =>
164163
val newTree = super.transform(tree)
165164
newTree.overwriteType(newTree.tpe.simplified)
166165
newTree
@@ -170,5 +169,5 @@ class Pickler extends Phase {
170169
case ex: TypeError =>
171170
report.error(ex, tree.srcPos)
172171
tree
173-
end TypeSimplifyTransformer
172+
end TypeSimplifier
174173
}

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
460460
)
461461
case Block(_, Closure(_, _, tpt)) if ExpandSAMs.needsWrapperClass(tpt.tpe) =>
462462
superAcc.withInvalidCurrentClass(super.transform(tree))
463+
case _: If | _: Match | _: Try =>
464+
val newTree = super.transform(tree)
465+
newTree.overwriteType(newTree.tpe.simplified)
466+
newTree
463467
case tree =>
464468
super.transform(tree)
465469
}

0 commit comments

Comments
 (0)