Scala Programming Language
  1. Scala Programming Language
  2. SI-6957

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: Scala 2.9.2, Scala 2.9.3-RC1, Scala 2.10.0, Scala 2.11.0-M1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Tested under Win7 with Scala 2.9.2 in Eclipse, latest Java 7 Runtime Environment

      Description

      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: <init> signature: ()V) Expecting to find object/array on stack"

      1. Test.scala
        1 kB
        Joscha Drechsler

        Issue Links

          Activity

          Hide
          James Iry added a comment - - edited

          minimized

          class Foo 
          class Parent(f:Foo)
          class Child extends Parent({val x=new Foo{}; x})
          
          new Child
          
          Show
          James Iry added a comment - - edited minimized class Foo class Parent(f:Foo) class Child extends Parent({val x=new Foo{}; x}) new Child
          Hide
          James Iry added a comment -

          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
          
          Show
          James Iry added a comment - 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
          Hide
          James Iry added a comment - - edited

          Compare the non-working

          class Child extends Parent({val x=new Foo{}; x})
          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

          class Child extends Parent({new Foo{}})
          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;
          
          
          }
          
          Show
          James Iry added a comment - - edited Compare the non-working class Child extends Parent({val x=new Foo{}; x}) 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 class Child extends Parent({new Foo{}}) 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; }
          Hide
          Jason Zaugg added a comment -

          I think this is a variation of SI-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.

          Show
          Jason Zaugg added a comment - I think this is a variation of SI-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.
          Hide
          James Iry added a comment -

          Yup. Shall I close as duplicate?

          Show
          James Iry added a comment - Yup. Shall I close as duplicate?

            People

            • Assignee:
              James Iry
              Reporter:
              Joscha Drechsler
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development