Skip to content

Dotty Type Erasure for Scala 2 compound types is wrong #22525

Open
@hamzaremmal

Description

@hamzaremmal

Compiler version

a3dde8b

Minimized code

In the same spirit of #22515:

//> using scala 2.13.16
trait B
trait C

class Foo {
  type structural3a = { type SubB <: B; type SubCB <: C with SubB }
  def foo(b: structural3a#SubB with structural3a#SubCB): Unit = {}
}

Then use the classfiles from Scala 2 when compiling the second file with Scala 3

//> using scala 3.6.3
@main def Test =
  (new Foo).foo(null.asInstanceOf)

Output

Exception in thread "main" java.lang.NoSuchMethodError: 'void Foo.foo(C)'
	at s3$package$.Test(s3.scala:2)
	at Test.main(s3.scala:1)

Expectation

To not fail at runtime.

Notes

Issue discovered in #22517. Related to #22524.
I also find that the specification is very ambiguous about the erasure of compound types. In the sense where:

  • We claim that: The intersection dominator of a list of types $T_1,...,T_n$ is computed as follows. Let $T_{i_1},...,T_{i_m}$ be the subsequence of types $T_i$ which are not supertypes of some other type $T_j$...
  • What is the relation between $i$ and $j$ ($i &lt; j$, $i &gt; j$, we don't care) ?
  • What is the subsequence: The empty subsequence is valid here. Should it be the maximal one?
  • What if we have two classes, do we take the first class?

In this issue, these details can change the erasure of foo. I know that we will have to follow the implementation of Scala 2 anyway, but the spec should be clear about these details.

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