-
Notifications
You must be signed in to change notification settings - Fork 21
Compiler generates wrong code from some code using extractor #1697
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1697?orig=1 |
Justin Wick (justinwick) said: Also, I motion that someone create a script to make simple combinations of standalone code and expected output into a ParTest test. |
@paulp said:
I don't know what refusal it is giving you but fsc works for me. The exact case given above I fixed in r18184 but the general issue is not fixed so I left this open.
I second the motion! All those in favor of assert(Someone == JustinWick)? The motion is carried unanimously! |
@ingoem said: abstract class Term
case object Var extends Term
case object Abs extends Term
object Ex {
def unapply(t: Term): Option[Term] = {
println("unapply " + t)
t match {
case Abs => Some(t)
case _ => None
}
}
}
object Test extends Application {
(Abs, Var) match {
case (Abs, Ex(v)) => println("Hm") // Comment this line out to get "Success"
case (Ex(v), t) => println("Success")
case (a, b) if Value.unapply(a) != None => println("Fail")
}
}
|
@sschaef said: object MyListTest extends App {
val xs = MyList(1 to 5: _*)
xs match {
// case MyList(head) => println("no") // works fine
case head :: MyNil => println("no") // produces a MatchError
case MyList(head, tail @ _*) => println("yay")
}
}
object MyList {
def apply[A](a: A*): MyList[A] =
(a :\ empty[A]) { _ :: _ }
def empty[A]: MyList[A] = MyNil
def unapplySeq[A](a: MyList[A]): Option[Seq[A]] = {
var xs: List[A] = Nil
var ys = a
while (!ys.isEmpty) {
xs = ys.head :: xs
ys = ys.tail
}
Some(xs.reverse)
}
}
abstract class MyList[+A] {
def head: A
def tail: MyList[A]
def isEmpty: Boolean
def :: [B >: A](b: B): MyList[B] =
new ::(b, this)
}
case class :: [A](head: A, tail: MyList[A]) extends MyList[A] {
def isEmpty = false
}
case object MyNil extends MyList[Nothing] {
def head = throw new UnsupportedOperationException("nil head")
def tail = throw new UnsupportedOperationException("nil tail")
def isEmpty = true
} |
Commit Message Bot (anonymous) said: wraps the call to a bridged synthetic unapply(Seq) in a defensive if-test: if (x.isInstanceOf[expectedType]) real.unapply(x.asInstanceOf[expectedType]) else None NOTE: the test is WRONG, but it has to be due to #1697/#2337 -- once those are fixed, this one should generate the expected output |
@paulp said: |
I wrote following code and compiled it(scala 2.7.3.final).
I expects that "Add(Value, ?)" is displayed , but "?" is displayed.
Diassembling the compiled code, It seems that the compiler generates the code that skips pattern "Add(Value(),y)" when pattern "Num(y)" fails.
The text was updated successfully, but these errors were encountered: