Skip to content

Testpickling failure due to avoidance #2840

Closed
@odersky

Description

@odersky

Consider:

object Test {
  class Type
  def f(x: Type): Type = ???
  def g(xs: List[Type]): Int = {
    val ys = xs.map(f)
    ys.toSet.size
  }
}

If we run this with -Ytest-pickler like this:

dotc toSet.scala -Ytest-pickler -Xprint-types

We get:

 pickling difference for module class Test$ in toSet.scala, for details:
               |
               |  diff before-pickling.txt after-pickling.txt

The diff is here:

<       :scala.Int>@<106..164>
---
>       :=> scala.Int(scala.collection.immutable.Set[Test.Type]#size)>@<106..164>

The rhs of g has type Int before pickling but type Set[Type]#size after pickling.
The problem has to do with avoid. The type of the block before avoid
is ys.toSet.size.type. That type is illegal, because it refers to
the local variable ys. Typer fixes the type to be Int since
that's the expected type anyway. But the unpickler widens the type
to ys.toSet.size.type instead because it does not have an expected type.

The difference is minor and probably harmless for all purposes. But it raises a flag in the diffs. The best way to suppress this is probably by adding a case to PlainPrinter#homogenize to deal with this. But I am unsure what the right rule should be.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions