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

Extractor issue - compiler crashes or at runtime get java.lang.VerifyError

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0
    • Component/s: Pattern Matcher
    • Labels:
      None

      Description

      Running some pattern matchers causes either a compiler crash or at runtime a java.lang.!VerifyError.[[BR]]
      Which happens depends on exact structure of pattern match (see below code, or self-contained test file attached).
      [[BR]]

      /**
       * Demonstration of issue with Extractors. If lines 15/16 are not present, get at runtime:
       *
       * Exception in thread "main" java.lang.VerifyError: (class: ExtractorIssue$$, method: convert signature: (LTopProperty;)LMyProp;) Accessing value from uninitialized register 5
       *	at ExtractorIssue.main(ExtractorIssue.scala)
       *	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)]
       *
       * If lines 15/16 are present, the compiler crashes:
       *
       * fatal error (server aborted): not enough arguments for method body%3: (val p: MyProp[java.lang.String])MyProp[_33].
       * Unspecified value parameter p.
       */
      object ExtractorIssue {
      
        def main(args: Array[String]) {
          convert(new SubclassProperty)
        }
      
        def convert(prop: TopProperty): MyProp[_] = {
          prop match {
      
              ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
              //case SubclassSecondMatch(p) => p // if these lines are present, the compiler crashes. If commented, unsafe byte
              //case SecondMatch(p) => p         // byte code is generated, which causes a java.lang.VerifyError at runtime
              ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
              case SubclassMatch(p) => p
              case StandardMatch(p) => p
          }
        }
      }
      
      class TopProperty
      
      class StandardProperty extends TopProperty
      class SubclassProperty extends StandardProperty
      
      class SecondProperty extends TopProperty
      class SubclassSecondProperty extends StandardProperty
      
      trait MyProp[T]
      case class MyPropImpl[T] extends MyProp[T]
      
      object SubclassMatch {
      
        def unapply(prop: SubclassProperty) : Option[MyProp[String]] = {
          Some(new MyPropImpl)
        }
      
        def apply(prop: MyProp[String]) : SubclassProperty = {
          new SubclassProperty()
        }
      }
      
      object StandardMatch {
      
        def unapply(prop: StandardProperty) : Option[MyProp[String]] = {
          Some(new MyPropImpl)
        }
      
        def apply(prop: MyProp[String]) : StandardProperty = {
          new StandardProperty()
        }
      }
      
      object SubclassSecondMatch {
      
        def unapply(prop: SubclassSecondProperty) : Option[MyProp[BigInt]] = {
          Some(new MyPropImpl)
        }
      
        def apply(prop: MyProp[String]) : SubclassSecondProperty = {
          new SubclassSecondProperty()
        }
      }
      
      object SecondMatch {
      
        def unapply(prop: SecondProperty) : Option[MyProp[BigInt]] = {
          Some(new MyPropImpl)
        }
      
        def apply(prop: MyProp[String]) : SecondProperty = {
          new SecondProperty()
        }
      }
      

      === What is the expected behavior? ===

      Should pattern match.

      === What do you see instead? ===

      Crash, of compiler or runtime.

      === Additional information ===
      This seems similar to, but also possibly distinct from the following two issues:

      https://lampsvn.epfl.ch/trac/scala/ticket/3702 [[BR]]
      https://lampsvn.epfl.ch/trac/scala/ticket/3972 [[BR]]

      === What versions of the following are you using? ===

      • Scala: 2.8.1, 2.9RC1
      • Java: sunjdk\1.6.0_21
      • Operating system: Windows XP

        Activity

        Hide
        jhodkinson added a comment -

        Any update on this issue?

        Show
        jhodkinson added a comment - Any update on this issue?
        Hide
        Stefan Zeiger added a comment -

        With -Yvirtpatmat in master (scala-2.10.0.rdev-4208-2012-01-19-g58cb15c) the VerifyError is gone. The compiler crash still occurs with both, the old pattern matcher and the virtualized pattern matcher.

        Show
        Stefan Zeiger added a comment - With -Yvirtpatmat in master (scala-2.10.0.rdev-4208-2012-01-19-g58cb15c) the VerifyError is gone. The compiler crash still occurs with both, the old pattern matcher and the virtualized pattern matcher.
        Hide
        Paul Phillips added a comment -

        I find no crash with 2.10.0.rdev-4232-2012-01-22-g9a20086 under -Yvirtpatmat. I doubt it was fixed in that short span. Can you reconfirm it, and post details if it's reproducible? (I did uncomment the lines which are supposed to lead to a crash, and do crash without -Yvirtpatmat.)

        Show
        Paul Phillips added a comment - I find no crash with 2.10.0.rdev-4232-2012-01-22-g9a20086 under -Yvirtpatmat. I doubt it was fixed in that short span. Can you reconfirm it, and post details if it's reproducible? (I did uncomment the lines which are supposed to lead to a crash, and do crash without -Yvirtpatmat.)
        Hide
        Stefan Zeiger added a comment -

        Sorry, I can't reproduce this anymore. It's compiling just fine under 4208 and 4234 with -Yvirtpatmat. Leaving this ticket open for now because it's not fixed in the old patmat which is still the default.

        Show
        Stefan Zeiger added a comment - Sorry, I can't reproduce this anymore. It's compiling just fine under 4208 and 4234 with -Yvirtpatmat. Leaving this ticket open for now because it's not fixed in the old patmat which is still the default.
        Hide
        Paul Phillips added a comment -

        virtpatmat saves day, test in 8bc8b83f0b .

        Show
        Paul Phillips added a comment - virtpatmat saves day, test in 8bc8b83f0b .

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            jhodkinson
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development