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

match guard causes verify error #3705

Closed
scabug opened this issue Jul 26, 2010 · 4 comments
Closed

match guard causes verify error #3705

scabug opened this issue Jul 26, 2010 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jul 26, 2010

Paste the following in the REPL (r22631):

import scala.xml._
def updateNodes(ns: Seq[Node]): Seq[Node] =
  for(subnode <- ns) yield subnode match {
    case <d>{_}</d> if true => <d>abc</d>
    case Elem(prefix, label, attribs, scope, children @ _*) =>
      Elem(prefix, label, attribs, scope, updateNodes(children) : _*)
    case other => other
  }
updateNodes(<b />)

The result is:

java.lang.VerifyError: (class: $$anonfun$$updateNodes$$1, method: apply
    signature: (Lscala/xml/Node;)Lscala/xml/Node;) Accessing value from
    uninitialized register 17
        at .updateNodes(<console>:46)
        at .<init>(<console>:46)
        at .<clinit>(<console>)
        at RequestResult$$.<init>(<console>:9)

Notably, if the if true is removed, the generated classfile is ok. Also, the same code works under 2.7.7, so it's a regression.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 26, 2010

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 13, 2011

@matlik said:
This issue can be reproduced without a conditional on the match. The following seems to exhibit the same symptoms.

import scala.xml._
def test(node: Node){
  def p(ns: Seq[Node]){
    for(subnode <- ns) subnode match {
      case Elem(prefix, label, attribs, scope, Text(text)) => println("has single text child")
      case Elem(prefix, label, attribs, scope, child @ _*) => { println("has children"); p(child)}
    }
  }
  p(node.theSeq)
}
test(<a>b</a>)

It would appear that three criteria needed to be met in this case:

  • A more specific pattern comes first
  • The more general pattern uses the child @ _* notation
  • The more general pattern uses recursion.
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 13, 2011

daniele.bettella said:
bug confirmed in scala versions 2.8.0 final and 2.9.0.1

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 4, 2012

@paulp said:
virtpatmat saves day, test in 8bc8b83f0b .

@scabug scabug closed this May 4, 2012
@scabug scabug added this to the 2.10.0 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.