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

Pattern matching fails although a match exists #4124

Closed
scabug opened this issue Dec 31, 2010 · 4 comments
Closed

Pattern matching fails although a match exists #4124

scabug opened this issue Dec 31, 2010 · 4 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Dec 31, 2010

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===

scala> val body: AnyRef = <elem>hi</elem>
body: AnyRef = <elem>hi</elem>

scala> (body, "foo") match {
     |   case (node: Node, "bar") => "bye"
     |   case (ser: Serializable, "foo") => "hi"
     | }

=== What is the expected behavior? ===
print "hi"

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

scala.MatchError: (<elem>hi</elem>,foo)
        at .<init>(<console>:12)
        at .<clinit>(<console>)
        at RequestResult$$.<init>(<console>:9)
        at RequestResult$$.<clinit>(<console>)
        at RequestResult$$scala_repl_result(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$18.apply(Interpreter.scala:981)
        at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$18.apply(Interpreter.scala:981)
        at scala.util.control.Exception$$Catch.apply(Exception.scala:79)
        at scala...

=== Additional information ===
From @retronym:
scalac -Xprint:erasure is a more direct way to see how the pattern
match is translated.

<synthetic> val temp1: Tuple2 = new Tuple2(test.this.body(), "foo");
      if (temp1.ne(null))
        {
          <synthetic> val temp2: java.lang.Object = temp1._1();
          <synthetic> val temp3: java.lang.String =
temp1._2().$$asInstanceOf[java.lang.String]();
          if (temp2.$$isInstanceOf[scala.xml.Node]())
            {
              if (temp3.==("bar"))
                {
                  "bye"
                }
              else
                throw new MatchError(temp1)
            }
          else
            if (temp2.$$isInstanceOf[java.io.Serializable]())
              {
                if (temp3.==("foo"))
                  {
                    "hi"
                  }
                else
                  throw new MatchError(temp1)
              }
            else
              throw new MatchError(temp1)
        }
      else
        throw new MatchError(temp1)
    }

Seems like a close cousin of #2337 and #1697 r1r2. You can read some
commentary from Paul r3, from the build up to Scala 2.8.

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

  • Scala:2.8.1
  • Java:1.6
  • Operating system: windows 7 64
@scabug
Copy link
Author

scabug commented Dec 31, 2010

Imported From: https://issues.scala-lang.org/browse/SI-4124?orig=1
Reporter: Ittay Dror (ittayd)

@scabug
Copy link
Author

scabug commented Jan 4, 2011

@hubertp said:
Looks like your department, Paul.

@scabug
Copy link
Author

scabug commented May 12, 2012

@retronym said:
scala/scala#534

@scabug
Copy link
Author

scabug commented May 12, 2012

@retronym said:
Test case pending merge, works in master.

@scabug scabug closed this as completed May 12, 2012
@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants