Skip to content

use scala.runtime.Statics.ioobe. forward port of Scala 2 #7086 #23971

@xuwei-k

Description

@xuwei-k

Compiler version

3.7.3

Minimized code

scalac -Xprint:genBCode A.scala

case class A(x: Int)

Output

    override def productElement(n: Int): Object =
      Int.box(
        matchResult2[Int]: 
          {
            case val x3: Int = n
            if 0 == x3 then return[matchResult2] this._1() else ()
            throw new IndexOutOfBoundsException(Int.box(n).toString())
          }
      )
    override def productElementName(n: Int): String =
      matchResult3[String]: 
        {
          case val x4: Int = n
          if 0 == x4 then return[matchResult3] "x" else ()
          throw new IndexOutOfBoundsException(Int.box(n).toString())
        }

javap result

  public java.lang.Object productElement(int);
    descriptor: (I)Ljava/lang/Object;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=3, args_size=2
         0: iload_1
         1: istore_2
         2: iconst_0
         3: iload_2
         4: if_icmpne     14
         7: aload_0
         8: invokevirtual #90                 // Method _1:()I
        11: goto          29
        14: new           #92                 // class java/lang/IndexOutOfBoundsException
        17: dup
        18: iload_1
        19: invokestatic  #98                 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
        22: invokevirtual #102                // Method java/lang/Integer.toString:()Ljava/lang/String;
        25: invokespecial #105                // Method java/lang/IndexOutOfBoundsException."<init>":(Ljava/lang/String;)V
        28: athrow
        29: invokestatic  #98                 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
        32: areturn

Expectation

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions