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

Assigning an instance of an anonymous class to a variable and returning that variable in a super class constructor causes verify error #6957

Closed
scabug opened this issue Jan 10, 2013 · 6 comments

Comments

@scabug
Copy link

scabug commented Jan 10, 2013

instantiating a mixin object, for instance a "new WeakHashMap with SynchronizedMap" inside a code block whose result is used as a super-constructor parameter causes a java.lang.VerifyError. The same code works fine when removing the "with SynchronizedMap" mixin or when calling the code block as a "static" method on a companion object, but when written directly into the super call it fails.

The attached Test.scala App demonstrates this by implementing three subclasses of the same parent class, one for each described variant, and then instantiating them. The third case in the test is the broken one and causes the error upon execution.

The error is "java.lang.VerifyError: (class: Child, method: signature: ()V) Expecting to find object/array on stack"

@scabug
Copy link
Author

scabug commented Jan 10, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6957?orig=1
Reporter: Joscha Drechsler (misterd)
Assignee: @JamesIry
Affected Versions: 2.9.2, 2.9.3-RC1, 2.10.0, 2.11.0-M1
See #6666
Attachments:

  • Test.scala (created on Jan 10, 2013 2:45:49 PM UTC, 1095 bytes)

@scabug
Copy link
Author

scabug commented Jan 10, 2013

@JamesIry said (edited on Jan 10, 2013 3:12:42 PM UTC):
minimized

class Foo 
class Parent(f:Foo)
class Child extends Parent({val x=new Foo{}; x})

new Child

@scabug
Copy link
Author

scabug commented Jan 10, 2013

@JamesIry said:
These variations work fine

class Foo
class Parent(f:Foo)
class Child extends Parent({new Foo{}})

new Child

and

class Foo
class Parent(f:Foo)
class Child extends Parent({val x=new Foo; x})

new Child

@scabug
Copy link
Author

scabug commented Jan 10, 2013

@JamesIry said (edited on Jan 10, 2013 3:43:53 PM UTC):
Compare the non-working

{code}class Child extends Parent({val x=new Foo{}; x}){code}

javap -c -l -s -private Child
Compiled from "Test.scala"
public class Child extends Parent{
public Child();
  Signature: ()V
  Code:
   0:	aload_0
   1:	new	#12; //class Child$$anon$1
   4:	dup
   5:	aload_0
   6:	invokespecial	#15; //Method Child$$anon$1."<init>":(LChild;)V
   9:	astore_1
   10:	aload_1
   11:	invokespecial	#18; //Method Parent."<init>":(LFoo;)V
   14:	return

  LineNumberTable: 
   line 3: 0

  LocalVariableTable: 
   Start  Length  Slot  Name   Signature
   0      15      0    this       LChild;
   10      1      1    x       LFoo;


}

to the working
{code}class Child extends Parent({new Foo{}}){code}

javap -c -l -s -private Child
Compiled from "Test2.scala"
public class Child extends Parent{
public Child();
  Signature: ()V
  Code:
   0:	aload_0
   1:	new	#12; //class Child$$anon$1
   4:	dup
   5:	invokespecial	#14; //Method Child$$anon$1."<init>":()V
   8:	invokespecial	#17; //Method Parent."<init>":(LFoo;)V
   11:	return

  LineNumberTable: 
   line 3: 0

  LocalVariableTable: 
   Start  Length  Slot  Name   Signature
   0      12      0    this       LChild;


}

@scabug
Copy link
Author

scabug commented Jan 10, 2013

@retronym said:
I think this is a variation of #6666, see my test case in the comments:

https://issues.scala-lang.org/browse/SI-6666?focusedCommentId=61462&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-61462

The sane thing to do is forbid such constructs, but I haven't quite figured out where to put the check.

@scabug
Copy link
Author

scabug commented Jan 10, 2013

@JamesIry said:
Yup. Shall I close as duplicate?

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

1 participant