scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

java.lang.VerifyError for method in constructor #7306

Closed scabug closed 11 years ago

scabug commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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

scabug commented 11 years ago

@retronym said: No doubt a close cousin of #6666