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 matcher's use of equals inhibits important warnings #7456

Closed
scabug opened this issue May 5, 2013 · 6 comments
Closed

pattern matcher's use of equals inhibits important warnings #7456

scabug opened this issue May 5, 2013 · 6 comments

Comments

@scabug
Copy link

scabug commented May 5, 2013

How is Bippy, an A, ever going to be a List[A] ?

class A
final case class B(xs: List[A]) extends A
object Test {
  val Bippy = new A
  def f(x: A) = x match { case B(Bippy)        => true ; case _ => false }
  def g(x: A) = x match { case B(Bippy :: Nil) => true ; case _ => false }

  def main(args: Array[String]): Unit = {
    println(f(B(Bippy :: Nil)))
    println(g(B(Bippy :: Nil)))
  }
}
% scalac a.scala
% scala Test
false
true
@scabug
Copy link
Author

scabug commented May 5, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7456?orig=1
Reporter: @paulp
See #7211

@scabug
Copy link
Author

scabug commented May 5, 2013

@paulp said:
Oh, it's because it checks with equals. That is increasingly a problem for me.

@scabug
Copy link
Author

scabug commented May 5, 2013

@paulp said:
So actually I guess this is getting better, not worse because this:

class A
final case class B(xs: List[A]) extends A

object Test {
  def f(x: B) = x match { case B(x: A)          => true ; case _ => false }
  def g(x: B) = x match { case B((x: A) :: Nil) => true ; case _ => false }

  def main(args: Array[String]): Unit = {
    println(f(B(new A :: Nil)))
    println(g(B(new A :: Nil)))
  }
}

Compiles with no warning in 2.9, but warns in 2.10. Which I should know, having written the warning.

a.scala:5: warning: fruitless type test: a value of type List[A] cannot also be a A
  def f(x: B) = x match { case B(x: A)          => true ; case _ => false }
                                    ^
one warning found

@scabug
Copy link
Author

scabug commented May 5, 2013

@retronym said (edited on May 5, 2013 5:24:25 PM UTC):
Akin to #7211. Making A final fails the compile.

@scabug
Copy link
Author

scabug commented May 5, 2013

@paulp said:
Reopening for me to investigate an -Xlint warning.

@SethTisue
Copy link
Member

as spec'ed. needs SIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants