Skip to content

VerifyError for generic class with private constructor and self type #8064

Closed
@travisbrown

Description

@travisbrown

minimized code

class Foo[A] private(x: Int) { self => def this() = this(0) }

new Foo[String]()
Compiles but fails at runtime
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    rs$line$5$Foo.<init>()V @1: checkcast
  Reason:
    Type uninitializedThis (current frame, stack[0]) is not assignable to 'java/lang/Object'
  Current Frame:
    bci: @1
    flags: { flagThisUninit }
    locals: { uninitializedThis }
    stack: { uninitializedThis }
  Bytecode:
    0x0000000: 2ac0 0002 03b7 0015 b1                 

        at rs$line$6$.<init>(rs$line$6:1)
        at rs$line$6$.<clinit>(rs$line$6)
        at rs$line$6.res2(rs$line$6)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at dotty.tools.repl.Rendering.$anonfun$3(Rendering.scala:72)
        at scala.Option.map(Option.scala:242)
        at dotty.tools.repl.Rendering.valueOf(Rendering.scala:72)
        at dotty.tools.repl.Rendering.renderVal(Rendering.scala:95)
        at dotty.tools.repl.ReplDriver.displayMembers$3$$anonfun$3(ReplDriver.scala:291)
        at scala.collection.immutable.List.map(List.scala:219)
        at scala.collection.immutable.List.map(List.scala:79)
        at dotty.tools.repl.ReplDriver.displayMembers$6(ReplDriver.scala:291)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$3$$anonfun$2(ReplDriver.scala:317)
        at scala.Option.map(Option.scala:242)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$1(ReplDriver.scala:317)
        at dotty.tools.dotc.core.Phases.atPhase$$anonfun$1(Phases.scala:35)
        at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:25)
        at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:35)
        at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:75)
        at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:323)
        at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:245)
        at scala.util.Either.fold(Either.scala:189)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:247)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
        at dotty.tools.repl.Main$.main(Main.scala:6)
        at dotty.tools.repl.Main.main(Main.scala)

expectation

This works on Scala 2 and clearly should work. If you remove any of the following it's fine:

  • The private on constructor.
  • The self type.
  • The type parameter.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions