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 in case class constructor with PartialFunction #6819

Closed
scabug opened this issue Dec 15, 2012 · 2 comments
Closed

VerifyError in case class constructor with PartialFunction #6819

scabug opened this issue Dec 15, 2012 · 2 comments

Comments

@scabug
Copy link

scabug commented Dec 15, 2012

The following code results in a VerifyError:

object Bug {
  class C(pf: PartialFunction[Any, Any])
  case class D() extends C({ case e => e })
  def main(args: Array[String]) {
    D() // VerifyError
  }
}

Here is the exception trace:

java.lang.VerifyError: (class: Bug$D, method: <init> signature: ()V) Expecting to find object/array on stack
	at Bug$.main(Bug.scala:5)
	at Bug.main(Bug.scala)

The cause of the bug is that D's <init> passes this to the constructor of the anonymous subclass of PartialFunction before the <init> method of the superclass C is invoked.

Here is the bytecode for D():

public Bug$D();
  Code:
   Stack=4, Locals=1, Args_size=1
   0:	aload_0
   1:	new	#72; //class Bug$D$$anonfun$$init$$1
   4:	dup
   5:	aload_0
   6:	invokespecial	#75; //Method Bug$D$$anonfun$$init$$1."<init>":(LBug$D;)V
   9:	invokespecial	#78; //Method Bug$C."<init>":(Lscala/PartialFunction;)V
   12:	aload_0
   13:	invokestatic	#84; //Method scala/Product$class.$init$:(Lscala/Product;)V
   16:	return

The VerifyError occurs at the invokespecial at instruction 6, caused by the aload_0 at instruction 5.

Note that the PartialFunction does not refer to this, so passing it in is unnecessary.

@scabug
Copy link
Author

scabug commented Dec 15, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6819?orig=1
Reporter: Nate Nystrom (njnystrom)
Affected Versions: 2.10.0-RC5
Duplicates #6666

@scabug
Copy link
Author

scabug commented Dec 15, 2012

@paulp said:
Duplicate of satanic ticket #6666.

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