Skip to content

VerifyError when class has var parameter and extends another class #14265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bishabosha opened this issue Jan 13, 2022 · 2 comments
Closed

VerifyError when class has var parameter and extends another class #14265

bishabosha opened this issue Jan 13, 2022 · 2 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented Jan 13, 2022

Originally posted at https://contributors.scala-lang.org/t/verify-error-when-using-mutable-fields-in-parametric-enumeration/5531

Compiler version

I use Scala 3.1.0 (17.0.1, Java OpenJDK 64-Bit Server VM).

Minimized code

In this setting, I found a Verify Error when using mutable fields in parametric enumeration as follows:

enum A(c: Int):
  case B(var k: Int) extends A(k)

Output

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    A$B.<init>(I)V @7: invokevirtual
  Reason:
    Type uninitializedThis (current frame, stack[1]) is not assignable to 'A$B'
  Current Frame:
    bci: @7
    flags: { flagThisUninit }
    locals: { uninitializedThis, integer }
    stack: { uninitializedThis, uninitializedThis }
  Bytecode:
    0000000: 2a1b b500 1f2a 2ab6 0022 b700 24b1

	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
	at java.base/java.lang.Class.getMethodsRecursive(Class.java:3543)
	at java.base/java.lang.Class.getMethod0(Class.java:3529)
	at java.base/java.lang.Class.getMethod(Class.java:2225)
	at dotty.tools.scripting.ScriptingDriver.collectMainMethods$3(ScriptingDriver.scala:79)
	at dotty.tools.scripting.ScriptingDriver.$anonfun$3(ScriptingDriver.scala:88)
	at scala.collection.immutable.List.flatMap(List.scala:293)
	at dotty.tools.scripting.ScriptingDriver.detectMainClassAndMethod(ScriptingDriver.scala:89)
	at dotty.tools.scripting.ScriptingDriver.compileAndRun(ScriptingDriver.scala:34)
	at dotty.tools.scripting.Main$.main(Main.scala:43)
	at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:168)
	at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:175)
	at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)

Expectation

However, the following code does not throw any error:

enum A(c: Int):
  case B(k: Int) extends A(k)

I think that it happens because the compiled JVM bytecode tries to use the mutable field k before its initialization in A(k).

@smarter
Copy link
Member

smarter commented Feb 7, 2022

Also happens with non-enums (#14422):

class A {
  class B(z: Any) {}
  class C(var y: Any) extends B(y) {}
  val c = new C("bar")
}

@main def test() =
  new A

@smarter smarter changed the title VerifyError when enum class case has var parameter VerifyError when class has var parameter and extends another class Feb 7, 2022
@smarter
Copy link
Member

smarter commented Feb 7, 2022

Actually both of these issues are already fixed in 3.1.1.

@smarter smarter closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants