Skip to content

Pickling difference error with explicit nulls and unsafe nulls #14947

Closed
@noti0na1

Description

@noti0na1

I was trying to enable explicit nulls for all compiling. But I get several errors in BootstrappedOnlyCompilationTests.picklingWithCompiler test. See #14946

Minimized code

I am able to minimize some of the errors:

class C {
  def g: String | Null = ???

  def f =
    import scala.language.unsafeNulls
    if true then "" else g
}

Output

scalac -Xprint-types -Ytest-pickler -Yexplicit-nulls -color never Stest.scala

exception occurred while compiling Stest.scala
class dotty.tools.dotc.reporting.Diagnostic$Error at ?: pickling difference for class C in Stest.scala, for details:

  diff before-pickling.txt after-pickling.txt while compiling Stest.scalaException in thread "main" 
class dotty.tools.dotc.reporting.Diagnostic$Error at ?: pickling difference for class C in Stest.scala, for details:

  diff before-pickling.txt after-pickling.txt
        at dotty.tools.dotc.report$.error(report.scala:63)
        at dotty.tools.dotc.transform.Pickler.testSame(Pickler.scala:151)
        at dotty.tools.dotc.transform.Pickler.testUnpickler$$anonfun$2(Pickler.scala:138)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
        at scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:896)
        at dotty.tools.dotc.transform.Pickler.testUnpickler(Pickler.scala:139)
        at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:122)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:236)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:244)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:253)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:253)
        at dotty.tools.dotc.Run.compileSources(Run.scala:186)
        at dotty.tools.dotc.Run.compile(Run.scala:170)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

before-pickling.txt

<package <empty>.type {
  @SourceFile(<"Stest.scala":("Stest.scala" : String)>) class C() extends <
    <<new Object:Object>:((): Object)>
  ():Object> {
    def g: scala.Predef.String | scala.Null = 
      <scala.Predef.???:=> scala.Nothing>
    def f: scala.Predef.String = 
      <
        {
          <import <<scala:scala>.language:scala.language>.unsafeNulls:
            <import>.type
          >
          <if <true:(true : scala.Boolean)> then <"":("" : String)> else 
            <<this:(C.this : C)>.g:=> scala.Predef.String | scala.Null>
          :String>
        }
      :String>
  }
}:<empty>.type>

diff before-pickling.txt after-pickling.txt

15c15
<           :String>
---
>           :String | scala.Null>
17c17
<       :String>
---
>       :String | scala.Null>

It seems the if expression gets different types before and after pickling?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions