Skip to content

Signature of method taking generic array differs from Scala 2 #8349

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

Closed
som-snytt opened this issue Feb 20, 2020 · 0 comments · Fixed by #8361
Closed

Signature of method taking generic array differs from Scala 2 #8349

som-snytt opened this issue Feb 20, 2020 · 0 comments · Fixed by #8361

Comments

@som-snytt
Copy link
Contributor

minimized code

class C {
  def f[A](as: Array[A]) = 42
}

Compilation output

$ ~/bin/dotc vargen.scala && javap C
Compiled from "vargen.scala"
public class C {
  public C();
  public <A> int f(A[]);
}

expectation

Compiled from "vargen.scala"
public class C {
  public <A> int f(java.lang.Object);
  public C();
}
smarter added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2020
When T[] is erased to Object, it should get a Java generic signature of
Object and not of T<>. Fixed by reusing the same logic we have in
TypeErasure which replaces a bunch of weird code imported from scalac.

The new behavior differs in one case from scalac: `Array[_ <: Byte]`
gets a generic signature of `byte[]` instead of `Object`, but this is
consistent with how we handle erasure (which I think is OK because as
far as I can tell, we can't construct a value of type `Array[Nothing]`
with Dotty).
smarter added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2020
When T[] is erased to Object, it should get a Java generic signature of
Object and not of T<>. Fixed by reusing the same logic we have in
TypeErasure which replaces a bunch of weird code imported from scalac.

The new behavior differs in one case from scalac: `Array[_ <: Byte]`
gets a generic signature of `byte[]` instead of `Object`, but this is
consistent with how we handle erasure (which I think is OK because as
far as I can tell, we can't construct a value of type `Array[Nothing]`
with Dotty).
@nicolasstucki nicolasstucki linked a pull request Feb 24, 2020 that will close this issue
smarter added a commit to dotty-staging/dotty that referenced this issue Mar 3, 2020
When T[] is erased to Object, it should get a Java generic signature of
Object and not of T<>. Fixed by reusing the same logic we have in
TypeErasure which replaces a bunch of weird code imported from scalac.

The new behavior differs in one case from scalac: `Array[_ <: Byte]`
gets a generic signature of `byte[]` instead of `Object`, but this is
consistent with how we handle erasure (which I think is OK because as
far as I can tell, we can't construct a value of type `Array[Nothing]`
with Dotty).
smarter added a commit that referenced this issue Mar 3, 2020
Fix #8349: Generic signatures of generic arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants