Skip to content

Type erased for by-name parameters #13638

Closed
@jlprat

Description

@jlprat

When a method has by-name parameters its type it's erased in the generated bytecode.

Compiler version

3.0.2 and 3.1.0-RC2

Minimized code

object ByNameParam {
  def byNameParam(str: => String): Unit = {}
}

You can find a reproducer project here where one can compile with Scala 2.13.6, 3.0.2 and 3.1.0-RC2 and see the difference in bytecode between versions.

Output

$> javap ByNameParam.class

Compiled from "ByNameParam.scala"
public final class ByNameParam {
  public static void byNameParam(scala.Function0);
}

Expectation

This is the output of the same class when compiling against Scala 2.13.6.
$> javap ByNameParam.class

Compiled from "ByNameParam.scala"
public final class ByNameParam {
  public static void byNameParam(scala.Function0<java.lang.String>);
}

Please note the missing type parameter String on Function0.

Impact

Java interoperability will be affected by this bug as the String type is completely lost.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions