scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

VerifyError with weird circular reference in class def #9270

Open som-snytt opened 4 years ago

som-snytt commented 4 years ago

Minimized code

class C:
  object Foo extends Foo.Bar.Base:
    object Bar:
      class Base

@main def test() =
  val c = new C
  val x = new c.Foo.Bar.Base

Output

$ dotc -d /tmp nested.scala && dotr -classpath /tmp test
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    C$Foo$.<init>(LC;)V @19: invokevirtual
  Reason:
    Type uninitializedThis (current frame, stack[1]) is not assignable to 'C$Foo$'
  Current Frame:
    bci: @19
    flags: { flagThisUninit }
    locals: { uninitializedThis, 'C' }
    stack: { uninitializedThis, uninitializedThis }
  Bytecode:
    0000000: 2bc7 000b bb00 1959 b700 1cbf 2a2b b500
    0000010: 1e2a 2ab6 0022 b700 25b1
  Stackmap Table:
    same_frame(@12)

        at C.Foo(nested.scala:2)
        at nested$package$.test(nested.scala:8)
        at test.main(nested.scala:6)

Expectation

Anything besides a VerifyError.

odersky commented 3 years ago

This is still an issue in 2021.

xerial commented 3 years ago

I also observed a similar compilation error.

SethTisue commented 9 months ago

note that Scala 2.13.12 rejects object Foo extends Foo.Bar.Base { object Bar { class Base } } with "illegal cyclic reference involving object Foo"