Skip to content

@publicInBinary doesn't have any effect on secondary constructors #22498

Closed
@hamzaremmal

Description

@hamzaremmal

Compiler version

590691b

Minimized code

import scala.annotation.publicInBinary
import scala.annotation.experimental

@experimental
class Foo:
  @publicInBinary private def this(x: Int) = this()

Output

Using javap -p -v Foo.class, the result is the following:

Classfile ***/Foo.class
  Last modified 2 Feb 2025; size 407 bytes
  MD5 checksum 9ed610bef429f72592f6f692ae62ffd6
  Compiled from "playground.scala"
public class Foo
  minor version: 0
  major version: 52
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #2                          // Foo
  super_class: #4                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 3
Constant pool:
   #1 = Utf8               Foo
   #2 = Class              #1             // Foo
   #3 = Utf8               java/lang/Object
   #4 = Class              #3             // java/lang/Object
   #5 = Utf8               playground.scala
   #6 = Utf8               <init>
   #7 = Utf8               ()V
   #8 = NameAndType        #6:#7          // "<init>":()V
   #9 = Methodref          #4.#8          // java/lang/Object."<init>":()V
  #10 = Utf8               this
  #11 = Utf8               LFoo;
  #12 = Utf8               (I)V
  #13 = Utf8               x
  #14 = Methodref          #2.#8          // Foo."<init>":()V
  #15 = Utf8               I
  #16 = Utf8               Code
  #17 = Utf8               LineNumberTable
  #18 = Utf8               LocalVariableTable
  #19 = Utf8               MethodParameters
  #20 = Utf8               SourceFile
  #21 = Utf8               TASTY
  #22 = Utf8               Scala
{
  public Foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #9                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 6: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LFoo;

  private Foo(int);
    descriptor: (I)V
    flags: (0x0002) ACC_PRIVATE
    Code:
      stack=1, locals=2, args_size=2
         0: aload_0
         1: invokespecial #14                 // Method "<init>":()V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LFoo;
            0       5     1     x   I
    MethodParameters:
      Name                           Flags
      x                              final
}
SourceFile: "playground.scala"
  TASTY: length = 0x10 (unknown attribute)
   00 CE 00 B0 90 A9 58 8B 00 77 40 16 3F 7C 5A 1A

  Scala: length = 0x0 (unknown attribute)

Expectation

Follow SIP-52, specifically the following sentence: This annotation cannot be used on private/private[this] definitions. With the exception of class constructors

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions