Skip to content

Constructors are unnecessarily given Java generic signatures #10834

Closed
@dwijnand

Description

@dwijnand

Minimized code

class Foo[T]

Output

  public <T extends java.lang.Object> Foo();
    descriptor: ()V
[..]
    Signature: #9                           // <T:Ljava/lang/Object;>()V

Expectation

No Signature on the constructor. Compare against the equivalent Java:

$ echo 'class Foo<T> {}' > Foo.java && javac Foo.java && javap -v Foo
Classfile /d/mima/Foo.class
  Last modified 17 Dec 2020; size 243 bytes
  MD5 checksum 33fcdfd618f6e8ce83505acaa1f16ed2
  Compiled from "Foo.java"
class Foo<T extends java.lang.Object> extends java.lang.Object
  minor version: 0
  major version: 55
  flags: (0x0020) ACC_SUPER
  this_class: #2                          // Foo
  super_class: #3                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 1, attributes: 2
Constant pool:
   #1 = Methodref          #3.#12         // java/lang/Object."<init>":()V
   #2 = Class              #13            // Foo
   #3 = Class              #14            // java/lang/Object
   #4 = Utf8               <init>
   #5 = Utf8               ()V
   #6 = Utf8               Code
   #7 = Utf8               LineNumberTable
   #8 = Utf8               Signature
   #9 = Utf8               <T:Ljava/lang/Object;>Ljava/lang/Object;
  #10 = Utf8               SourceFile
  #11 = Utf8               Foo.java
  #12 = NameAndType        #4:#5          // "<init>":()V
  #13 = Utf8               Foo
  #14 = Utf8               java/lang/Object
{
  Foo();
    descriptor: ()V
    flags: (0x0000)
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0
}
Signature: #9                           // <T:Ljava/lang/Object;>Ljava/lang/Object;
SourceFile: "Foo.java"

(Signature #9 is the class Signature.) Scala 2 doesn't emit this, which I perceive as correct.

This came up in the context of trialing MiMa on different versions of a library compiled with the Scala 3 compiler and some changes are resulting in additional, unexpected constructor signature changes - however signature checking is an opt-in feature of MiMa, so this wouldn't affect all MiMa users.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions