Skip to content

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

Open
@hamzaremmal

Description

@hamzaremmal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions