Skip to content

VerifyError in super init block #12501

Open
@som-snytt

Description

@som-snytt

reproduction steps

Welcome to Scala 2.13.7 (OpenJDK 64-Bit Server VM, Java 17).
Type in expressions for evaluation. Or try :help.

scala> class X(x: Int) { def f = x }
class X

scala> class Y extends X({ case class C(c: Int) ; object C { val x = 42 } ; C(17).c + C.x })
class Y

scala> new Y().f
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Y.<init>(L$iw;)V @32: invokespecial
  Reason:
    Type uninitializedThis (current frame, stack[2]) is not assignable to 'Y'
  Current Frame:
    bci: @32
    flags: { flagThisUninit }
    locals: { uninitializedThis, '$iw', 'scala/runtime/LazyRef' }
    stack: { uninitializedThis, '$iw', uninitializedThis, 'scala/runtime/LazyRef', '$iw' }
  Bytecode:
    0000000: 2bc7 0005 01bf 2a2b b500 1c2a b200 40b6
    0000010: 0044 b600 47bb 0024 59b7 004a 4d2a 2c2b
    0000020: b700 4c10 11b6 0050 b600 542a 2c2b b700
    0000030: 4cb6 0057 60b7 005a b1
  Stackmap Table:
    same_frame(@6)

  ... 32 elided

also for completeness

scala> class C extends { val x = { case class C(c: Int) ; object C { val x = 42 } ; C(17).c + C.x } } with AnyRef { def f = x }
                       ^
       warning: early initializers are deprecated; they will be replaced by trait parameters in 3.0, see the migration guide on avoiding var/val in traits.
class C

scala> new C().f
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    C.<init>(L$iw;)V @22: invokespecial
  Reason:
    Type uninitializedThis (current frame, stack[0]) is not assignable to 'C'
  Current Frame:
    bci: @22
    flags: { flagThisUninit }
    locals: { uninitializedThis, '$iw', top, 'scala/runtime/LazyRef' }
    stack: { uninitializedThis, 'scala/runtime/LazyRef', '$iw' }
  Bytecode:
    0000000: 2bc7 0005 01bf 2a2b b500 21bb 0027 59b7
    0000010: 0040 4e2a 2d2b b700 4210 11b6 0046 b600
    0000020: 492a 2d2b b700 42b6 004a 603d 2a1c b500
    0000030: 182a b700 4bb1
  Stackmap Table:
    same_frame(@6)

  ... 32 elided

problem

Previously noted scala/scala#5550 (comment)

Maybe a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions