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

Type erased for by-name parameters #13638

Closed
jlprat opened this issue Sep 29, 2021 · 1 comment · Fixed by #14310
Closed

Type erased for by-name parameters #13638

jlprat opened this issue Sep 29, 2021 · 1 comment · Fixed by #14310
Assignees
Labels
Milestone

Comments

@jlprat
Copy link

jlprat commented Sep 29, 2021

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.

@smarter smarter added this to the 3.2.0 milestone Dec 8, 2021
@anatoliykmetyuk anatoliykmetyuk added the Spree Suitable for a future Spree label Jan 10, 2022
@smarter
Copy link
Member

smarter commented Jan 10, 2022

Java generic signatures are generated by https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala, and by-names are represented as ExprType, presumably the issue is that we don't generate a generic signature at all here and we just need to a case ExprType that returns true to https://github.com/lampepfl/dotty/blob/44d907f19a193707920fd0729d1627f472e3bf1d/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala#L455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants