bug icon indicating copy to clipboard operation
bug copied to clipboard

Incorrect generic signature with shadowing type parameter

Open lrytz opened this issue 1 month ago • 0 comments

Given

abstract class C[T] {
  def x: T
  def m[T] = x
}

The method m has generic signature <T:Ljava/lang/Object;>()TT;, which is not correct.

Java usage String t(C<String> c) { return c.<Object>m(); } results in a compiler error

U.java:2: error: incompatible types: Object cannot be converted to String
    String t(C<String> c) { return c.<Object>m(); }
                                              ^

Scala 3 fix in https://github.com/scala/scala3/pull/24567 and some follow ups (https://github.com/scala/scala3/pull/24621, https://github.com/scala/scala3/pull/24684)

Also, given

abstract class C[T] {
  val x: T
  class I[T <: x.type]
}

the class C$I has signature <T:TT;>Ljava/lang/Object;, which I assume is also wrong (to be confirmed).

lrytz avatar Dec 08 '25 09:12 lrytz