Skip to content

Commit bab2edc

Browse files
committed
Fix safe-init error in TreePickler
When bootstrapping the compiler with the `-Ysafe-init` flag, we would get the following error: ``` [error] -- Error: /*************/dotty/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala:24:20 [error] 24 | pickler.newSection(ASTsSection, buf) [error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [error] |Call method TreePickler.this.pickler.newSection("ASTs", [error] | dotty.tools.dotc.core.tasty.TreePickler.this.buf [error] |) on a value with an unknown initialization. Calling trace: [error] | -> val treePkl: TreePickler = new TreePickler(this) [ TastyPickler.scala:85 ] [error] | -> class TreePickler(pickler: TastyPickler) { [ TreePickler.scala:22 ] ``` This supresses the warning for this case. Review by @liufengyun
1 parent 20842cf commit bab2edc

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,4 @@ class TastyPickler(val rootCls: ClassSymbol) {
8181
assert(all.length == totalSize && all.bytes.length == totalSize, s"totalSize = $totalSize, all.length = ${all.length}, all.bytes.length = ${all.bytes.length}")
8282
all.bytes
8383
}
84-
85-
val treePkl: TreePickler = new TreePickler(this)
8684
}

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.dotc.core.Decorators._
88
import dotty.tools.dotc.core.Mode
99
import dotty.tools.dotc.core.Symbols._
1010
import dotty.tools.dotc.core.Types._
11-
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
11+
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter, TreePickler }
1212
import dotty.tools.dotc.core.tasty.DottyUnpickler
1313
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1414
import dotty.tools.dotc.report
@@ -154,7 +154,7 @@ object PickledQuotes {
154154
private def pickle(tree: Tree)(using Context): Array[Byte] = {
155155
quotePickling.println(i"**** pickling quote of\n$tree")
156156
val pickler = new TastyPickler(defn.RootClass)
157-
val treePkl = pickler.treePkl
157+
val treePkl = new TreePickler(pickler)
158158
treePkl.pickle(tree :: Nil)
159159
treePkl.compactify()
160160
if tree.span.exists then

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Pickler extends Phase {
6868
if ctx.settings.YtestPickler.value then
6969
beforePickling(cls) = tree.show
7070
picklers(cls) = pickler
71-
val treePkl = pickler.treePkl
71+
val treePkl = new TreePickler(pickler)
7272
treePkl.pickle(tree :: Nil)
7373
val positionWarnings = new mutable.ListBuffer[String]()
7474
val pickledF = inContext(ctx.fresh) {

0 commit comments

Comments
 (0)