Skip to content

Incorrect generic signature with shadowing type parameter #13144

@lrytz

Description

@lrytz

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 scala/scala3#24567 and some follow ups (scala/scala3#24621, scala/scala3#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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions