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 for method in constructor #7306

Closed
scabug opened this issue Mar 27, 2013 · 3 comments
Closed

java.lang.VerifyError for method in constructor #7306

scabug opened this issue Mar 27, 2013 · 3 comments

Comments

@scabug
Copy link

scabug commented Mar 27, 2013

An anonymous method in a constructor is generated as a static method but the code expects to be called as a virtual method, resulting in the error:

java.lang.VerifyError: (class: com/sosnoski/codejam/shifting/Application$Map, method: setPaths$1 signature: (ILscala/collection/immutable/List;)V) Register 0 contains wrong type

Here's a partial disassembly:

private static final void setPaths$1(int, scala.collection.immutable.List)

0 aload_1
1 astore_3
2 aload_3
3 instanceof scala.collection.immutable.$colon$colon
6 ifeq 118
9 aload_3
10 checkcast scala.collection.immutable.$colon$colon
13 astore %4
15 aload %4
17 invokevirtual scala.collection.immutable.$colon$colon.hd$1 ()Ljava/lang/Object;():Object
20 checkcast String
23 astore %5
25 aload %5
27 astore %6
29 getstatic Application$.MODULE$ Lcom/sosnoski/codejam/lost/Application$;
32 aload %6
34 invokevirtual Application$.splitValues (Ljava/lang/String;)Lscala/collection/immutable/List;(String):scala.collection.immutable.List
37 astore %7
39 aload_0
40 getfield lefts [I

It's trying to load the field "lefts" from the class reference at position 0, but with a static call it's not there. It's also looking for the int value at position 1 and the list at position 2.

Here's the corresponding source code:

package com.sosnoski.codejam.shifting

import scala.annotation.tailrec

class Map(lefts: Array[Int]) {
  def this() = {
    this(null)
    @tailrec
    def setPaths(index: Int) {
      lefts(index) = 0
      setPaths(index + 1)
    }
  }
}

object Test {
  new Map()
}

Complete project attached.

@scabug
Copy link
Author

scabug commented Mar 27, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7306?orig=1
Reporter: Dennis Sosnoski (dsosnoski)
Assignee: @JamesIry
Affected Versions: 2.10.1
See #6666
Duplicates #6666
Attachments:

@scabug
Copy link
Author

scabug commented Mar 27, 2013

Dennis Sosnoski (dsosnoski) said:
Moving setPaths() out of the constructor (while making it private for tailrec) eliminates the problem.

@scabug
Copy link
Author

scabug commented Mar 27, 2013

@retronym said:
No doubt a close cousin of #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

1 participant