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

Scala 2 erasure drops the generic type T in the presence of Array[T] #13065

Open
hamzaremmal opened this issue Dec 3, 2024 · 0 comments
Open
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

Comments

@hamzaremmal
Copy link
Member

Reproduction steps

Scala version: 2.13.15

object Foo {
    def fill[T](elem: => T): Array[T] = ???
}

Problem

The genric signature in the bytecode should include the generic type T. Currently, it is not the case:

scalac foo.scala; javap Foo.class
Compiled from "foo.scala"
public final class Foo {
  public static java.lang.Object fill(scala.Function0);
}

Scala 3 does a better job here:

scalac foo.scala -Ycompile-scala2-library; javap foo.class
Compiled from "foo.scala"
public final class Foo {
  public static <T> java.lang.Object fill(scala.Function0<T>);
}

note that the -Ycompile-scala2-library is not really necessary

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

2 participants