Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hamzaremmal opened this issue Feb 5, 2025 · 1 comment
Open

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

hamzaremmal opened this issue Feb 5, 2025 · 1 comment

Comments

@hamzaremmal
Copy link
Member

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.

@smarter
Copy link
Member

smarter commented Feb 5, 2025

I don't think there's any hope of a proper spec for erasure of intersection types in Scala 2 unfortunately, as documented in https://github.com/scala/scala3/blob/main/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Erasure.scala, it is hopelessly dependent on implementation details (hash-consing of certaint types, transformation phases doing simplifications, ...)

@hamzaremmal hamzaremmal removed their assignment Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants