Skip to content
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

java.lang.VerifyError: Constructor must call super() or this() before return #16496

Closed
maloku opened this issue Dec 10, 2022 · 1 comment
Closed
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html itype:bug itype:crash

Comments

@maloku
Copy link

maloku commented Dec 10, 2022

Compiler version

scala version: 3.2.1

Minimized code

This is the minimal code I could get which reproduces the issue when -coverage-out:target/cov

//SomeValue.scala
package coveragebug


import scala.collection.immutable.ArraySeq
import scala.reflect.ClassTag

opaque type SomeValue = Boolean | BooleanArray //some more types

object SomeValue {
  def apply(value: Boolean | BooleanArray): SomeValue = value
}

extension (sv: SomeValue)
  def valueType: ValueType[?] = sv match
    case _:Boolean       => ValueType.booleanType
    case _: BooleanArray => ValueType.booleanArrayType
sealed trait WrappedBooleanArray {
  type U
  type V = ArraySeq[U]

  def value: V
}

final case class BooleanArray(override val value: ArraySeq[Boolean]) extends WrappedBooleanArray {
  override type U = Boolean
}
sealed trait ValueType[U] {

  def boo: Int
  //some other methods
}
sealed abstract class ArrayType[T: ValueType: ClassTag] extends ValueType[ArraySeq[T]]:
  private val sn = summon[ValueType[T]]
  override def boo: Int  = sn.boo + 1
end ArrayType


object ValueType {
  //some more givens

  given booleanType: ValueType[Boolean] with {
    def boo = 1

  }

  given booleanArrayType: ArrayType[Boolean] with {
    //some other methods
  }
}

It happens only when someArray.valueType

//SomeValueSpec.scala  in test sources
import org.scalatest.flatspec.AnyFlatSpec
import scala.collection.immutable.ArraySeq
import scala.reflect.ClassTag


class SomeValueSpec extends AnyFlatSpec {
  "Test" should "not crash" in {

    val someValue: SomeValue = SomeValue(false)
    val someArray: SomeValue = SomeValue(BooleanArray(ArraySeq(false, true)))
    someValue.valueType
    someArray.valueType

  }
}
//build.sbt
ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.2.1"

lazy val root = (project in file("."))
  .settings(
    name := "coveragebug",
    scalacOptions ++= Seq("-coverage-out", "target/cov"),
    libraryDependencies ++= Seq(
      "org.scalatest"   %% "scalatest"       % "3.2.14" % Test
    )
  )

Output (click arrow to expand)

```Scala [info] welcome to sbt 1.8.0 (GraalVM Community Java 11.0.17) ... [info] SomeValueSpec: [info] Test [info] coveragebug.SomeValueSpec *** ABORTED *** [info] java.lang.VerifyError: Constructor must call super() or this() before return [info] Exception Details: [info] Location: [info] coveragebug/ValueType$booleanArrayType$.()V @0: return [info] Reason: [info] Error exists in the bytecode [info] Bytecode: [info] 0000000: b1 [info] at coveragebug.SomeValue$package$.valueType(SomeValue.scala:16) [info] at coveragebug.SomeValueSpec.testFun$proxy1$1(SomeValueSpec.scala:18) [info] at coveragebug.SomeValueSpec.$init$$$anonfun$1(SomeValueSpec.scala:13) [info] at org.scalatest.Transformer.apply$$anonfun$1(Transformer.scala:22) [info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85) [info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:31) [info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) [info] at org.scalatest.Transformer.apply(Transformer.scala:22) [info] at org.scalatest.Transformer.apply(Transformer.scala:21) [info] at org.scalatest.flatspec.AnyFlatSpecLike$$anon$5.apply(AnyFlatSpecLike.scala:1697) [info] ... [error] java.lang.VerifyError: Constructor must call super() or this() before return [error] Exception Details: [error] Location: [error] coveragebug/ValueType$booleanArrayType$.()V @0: return [error] Reason: [error] Error exists in the bytecode [error] Bytecode: [error] 0000000: b1 [error] [error] at coveragebug.SomeValue$package$.valueType(SomeValue.scala:16) [error] at coveragebug.SomeValueSpec.testFun$proxy1$1(SomeValueSpec.scala:18) [error] at coveragebug.SomeValueSpec.$init$$$anonfun$1(SomeValueSpec.scala:13) [error] at org.scalatest.Transformer.apply$$anonfun$1(Transformer.scala:22) [error] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85) [error] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:31) [error] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) [error] at org.scalatest.Transformer.apply(Transformer.scala:22) [error] at org.scalatest.Transformer.apply(Transformer.scala:21) [error] at org.scalatest.flatspec.AnyFlatSpecLike$$anon$5.apply(AnyFlatSpecLike.scala:1697) [error] at org.scalatest.TestSuite.withFixture(TestSuite.scala:196) [error] at org.scalatest.TestSuite.withFixture$(TestSuite.scala:138) [error] at org.scalatest.flatspec.AnyFlatSpec.withFixture(AnyFlatSpec.scala:1685) [error] at org.scalatest.flatspec.AnyFlatSpecLike.invokeWithFixture$1(AnyFlatSpecLike.scala:1703) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTest$$anonfun$1(AnyFlatSpecLike.scala:1707) [error] at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTest(AnyFlatSpecLike.scala:1707) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTest$(AnyFlatSpecLike.scala:51) [error] at coveragebug.SomeValueSpec.org$scalatest$BeforeAndAfter$$super$runTest(SomeValueSpec.scala:12) [error] at org.scalatest.BeforeAndAfter.runTest(BeforeAndAfter.scala:213) [error] at org.scalatest.BeforeAndAfter.runTest$(BeforeAndAfter.scala:118) [error] at coveragebug.SomeValueSpec.runTest(SomeValueSpec.scala:12) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTests$$anonfun$1(AnyFlatSpecLike.scala:1765) [error] at org.scalatest.SuperEngine.traverseSubNodes$1$$anonfun$1(Engine.scala:413) [error] at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] at scala.collection.immutable.List.foreach(List.scala:333) [error] at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:429) [error] at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390) [error] at org.scalatest.SuperEngine.traverseSubNodes$1$$anonfun$1(Engine.scala:427) [error] at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] at scala.collection.immutable.List.foreach(List.scala:333) [error] at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:429) [error] at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396) [error] at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTests(AnyFlatSpecLike.scala:1765) [error] at org.scalatest.flatspec.AnyFlatSpecLike.runTests$(AnyFlatSpecLike.scala:51) [error] at org.scalatest.flatspec.AnyFlatSpec.runTests(AnyFlatSpec.scala:1685) [error] at org.scalatest.Suite.run(Suite.scala:1114) [error] at org.scalatest.Suite.run$(Suite.scala:564) [error] at org.scalatest.flatspec.AnyFlatSpec.org$scalatest$flatspec$AnyFlatSpecLike$$super$run(AnyFlatSpec.scala:1685) [error] at org.scalatest.flatspec.AnyFlatSpecLike.run$$anonfun$1(AnyFlatSpecLike.scala:1810) [error] at org.scalatest.SuperEngine.runImpl(Engine.scala:535) [error] at org.scalatest.flatspec.AnyFlatSpecLike.run(AnyFlatSpecLike.scala:1810) [error] at org.scalatest.flatspec.AnyFlatSpecLike.run$(AnyFlatSpecLike.scala:51) [error] at coveragebug.SomeValueSpec.org$scalatest$BeforeAndAfter$$super$run(SomeValueSpec.scala:12) [error] at org.scalatest.BeforeAndAfter.run(BeforeAndAfter.scala:273) [error] at org.scalatest.BeforeAndAfter.run$(BeforeAndAfter.scala:118) [error] at coveragebug.SomeValueSpec.org$scalatest$BeforeAndAfterAll$$super$run(SomeValueSpec.scala:12) [error] at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213) [error] at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:217) [error] at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:135) [error] at coveragebug.SomeValueSpec.run(SomeValueSpec.scala:12) [error] at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321) [error] at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517) [error] at sbt.TestRunner.runTest$1(TestFramework.scala:147) [error] at sbt.TestRunner.run(TestFramework.scala:162) [error] at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:330) [error] at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:290) [error] at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:330) [error] at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:330) [error] at sbt.TestFunction.apply(TestFramework.scala:342) [error] at sbt.Tests$.$anonfun$toTask$1(Tests.scala:435) [error] at sbt.std.Transform$$anon$3.$anonfun$apply$2(Transform.scala:46) [error] at sbt.std.Transform$$anon$4.work(Transform.scala:68) [error] at sbt.Execute.$anonfun$submit$2(Execute.scala:282) [error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) [error] at sbt.Execute.work(Execute.scala:291) [error] at sbt.Execute.$anonfun$submit$1(Execute.scala:282) [error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) [error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:64) [error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [error] at java.base/java.lang.Thread.run(Thread.java:829) [error] (Test / executeTests) java.lang.VerifyError: Constructor must call super() or this() before return [error] Exception Details: [error] Location: [error] coveragebug/ValueType$booleanArrayType$.()V @0: return [error] Reason: [error] Error exists in the bytecode [error] Bytecode: [error] 0000000: b1 ```
@maloku maloku added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 10, 2022
@odersky odersky added area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 10, 2022
@TheElectronWill
Copy link
Contributor

Thank you for the report and the reproducible example!
I've tested that the crash is fixed by dotty 3.2.2-RC1 and above (thanks to #16235)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html itype:bug itype:crash
Projects
None yet
Development

No branches or pull requests

3 participants