# Verify Error when using mutable fields in parametric enumeration

**URL:** <https://contributors.scala-lang.org/t/verify-error-when-using-mutable-fields-in-parametric-enumeration/5531>\
**Category:** Compiler\
**Created:** [January 13, 2022, 4:20am UTC](https://contributors.scala-lang.org/t/verify-error-when-using-mutable-fields-in-parametric-enumeration/5531 "2022-01-13T04:20:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![workstudy-zero](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/workstudy-zero/32/2323_2.png) [@workstudy-zero](https://contributors.scala-lang.org/u/workstudy-zero)\
**Post date:** [January 13, 2022, 4:20am UTC](https://contributors.scala-lang.org/t/verify-error-when-using-mutable-fields-in-parametric-enumeration/5531/1 "2022-01-13T04:20:30Z")

</div>

I use Scala 3.1.0 (17.0.1, Java OpenJDK 64-Bit Server VM).  
In this setting, I found a _Verify Error_ when using mutable fields in parametric enumeration as follows:

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

```

with the following error message:

```auto
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)

```

However, the following code does not throw any error:

```scala
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)`.

---

<div class="post-metadata">

**Author:** ![bishabosha](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/bishabosha/32/3101_2.png) [@bishabosha](https://contributors.scala-lang.org/u/bishabosha)\
**Post date:** [January 13, 2022, 8:51am UTC](https://contributors.scala-lang.org/t/verify-error-when-using-mutable-fields-in-parametric-enumeration/5531/2 "2022-01-13T08:51:57Z")

</div>

Hi, thank you for reporting! I have opened a issue on GitHub for this at [VerifyError when enum class case has var parameter · Issue #14265 · lampepfl/dotty · GitHub](https://github.com/lampepfl/dotty/issues/14265)
