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

VerifyError when using a matcher in a parent constructor call #8733

Closed
scabug opened this issue Jul 18, 2014 · 7 comments
Closed

VerifyError when using a matcher in a parent constructor call #8733

scabug opened this issue Jul 18, 2014 · 7 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jul 18, 2014

The following code causes a VerifyError to get thrown as soon as a Child instance is created:

// error.scala
abstract class Parent(val description: String)

class Child(val opt: Option[String])
  extends Parent(
    { opt match {
        case Some(o) => o
        case None => "nope"
    }})

object Main extends App {
  val javaVersion = System.getProperty("java.version")
  println(s"${javaVersion}")

  new Child(Some("Foo"))
}
// build.sbt
name := "verify-test"

scalaVersion := "2.11.1"

scalacOptions += "-target:jvm-1.7"

Removing the target JVM results in bytecode that doesn't cause a VerifyError.

Also running this on Java 1.7.0 update 60 or lower does not cause the error to be thrown.

@scabug
Copy link
Author

scabug commented Jul 18, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8733?orig=1
Reporter: Michael Stringer (stringbean)
Affected Versions: 2.10.4, 2.11.1

@scabug
Copy link
Author

scabug commented Jul 18, 2014

@som-snytt said:
FWIW,

$ scalac -target:jvm-1.7 badchild.scala && scala badchild.Main
version 2.11.1, 1.8.0_05

//import util.Properties._
//Console println s"$versionString, $javaVersion"

@scabug
Copy link
Author

scabug commented Jul 21, 2014

Michael Stringer (stringbean) said:
Tested on Java 8u11 and it failed:

$ sbt run
[info] Set current project to verify-test (in build file:/home/mike/scala-crash/)
[info] Compiling 1 Scala source to /home/mike/scala-crash/target/scala-2.11/classes...
[info] Running Main
version 2.11.1, 1.8.0_11
[error] (run-main-0) java.lang.VerifyError: Bad <init> method call from inside of a branch
[error] Exception Details:
[error]   Location:
[error]     Child.<init>(Lscala/Option;)V @52: invokespecial
[error]   Reason:
[error]     Error exists in the bytecode
[error]   Bytecode:
[error]     0000000: 2a2b b500 0e2a 2b4d 2cc1 0014 9900 182c
[error]     0000010: c000 144e 2db6 0018 c000 1a3a 0419 043a
[error]     0000020: 05a7 0011 b200 202c b600 2699 000d 1228
[error]     0000030: 3a05 1905 b700 2bb1 bb00 2d59 2cb7 0030
[error]     0000040: bf
[error]   Stackmap Table:
[error]     full_frame(@36,{UninitializedThis,Object[#52],Object[#52]},{UninitializedThis})
[error]     full_frame(@50,{UninitializedThis,Object[#52],Object[#52],Top,Top,Object[#26]},{UninitializedThis})
[error]     full_frame(@56,{UninitializedThis,Object[#52],Object[#52]},{UninitializedThis})
java.lang.VerifyError: Bad <init> method call from inside of a branch
Exception Details:
  Location:
    Child.<init>(Lscala/Option;)V @52: invokespecial
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2a2b b500 0e2a 2b4d 2cc1 0014 9900 182c
    0000010: c000 144e 2db6 0018 c000 1a3a 0419 043a
    0000020: 05a7 0011 b200 202c b600 2699 000d 1228
    0000030: 3a05 1905 b700 2bb1 bb00 2d59 2cb7 0030
    0000040: bf
  Stackmap Table:
    full_frame(@36,{UninitializedThis,Object[#52],Object[#52]},{UninitializedThis})
    full_frame(@50,{UninitializedThis,Object[#52],Object[#52],Top,Top,Object[#26]},{UninitializedThis})
    full_frame(@56,{UninitializedThis,Object[#52],Object[#52]},{UninitializedThis})

	at Main$.delayedEndpoint$Main$1(error.scala:15)
	at Main$delayedInit$body.apply(error.scala:12)
	at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:383)
	at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
	at scala.App$class.main(App.scala:76)
	at Main$.main(error.scala:12)
	at Main.main(error.scala)
	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:483)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
	at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 4 s, completed 21-Jul-2014 11:21:19

@scabug
Copy link
Author

scabug commented Jul 21, 2014

Michael Stringer (stringbean) said:
Found this on the Java bug tracker: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8051012

@scabug
Copy link
Author

scabug commented Mar 9, 2016

@som-snytt said:

Welcome to Scala 2.12.0-M3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> class Parent(val i: Int) { def this(p: Parent) = this(p.i) ; if (i > 40) throw new IllegalArgumentException }
defined class Parent

scala> class Child extends Parent({ val p = try new Parent(42) catch { case _: IllegalArgumentException => throw new RuntimeException }; p})
defined class Child

scala> new Child
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Child.<init>()V @2: invokespecial
  Reason:
    Type uninitializedThis (current frame, stack[1]) is not assignable to 'Child'
  Current Frame:
    bci: @2
    flags: { flagThisUninit }
    locals: { uninitializedThis }
    stack: { uninitializedThis, uninitializedThis }
  Bytecode:
    0x0000000: 2a2a b700 254c 2bb7 0028 b1

  ... 28 elided

@som-snytt
Copy link

Welcome to Scala 2.12.9 (OpenJDK 64-Bit Server VM, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

class Parent(val i: Int) { def this(p: Parent) = this(p.i) ; if (i > 40) throw new IllegalArgumentException }
class Child extends Parent({ val p = try new Parent(42) catch { case _: IllegalArgumentException => throw new RuntimeException }; p}) 

// Exiting paste mode, now interpreting.

defined class Parent
defined class Child

scala> new Child
java.lang.RuntimeException
  at Child.liftedTree1$1(<console>:12)
  ... 29 elided

@som-snytt
Copy link

som-snytt commented Jan 27, 2020

Progressed in 2.12.0-M5

Test scala/scala#8667

@SethTisue SethTisue added this to the 2.12.0 milestone Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants