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
patmat strips unused bindings, but affects semantics #5024
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5024?orig=1 |
@acruise said: |
@paulp said: |
@retronym said: |
@adriaanm said: |
@paulp said: scala> val s: Seq[Nothing] = Vector.empty
s: Seq[Nothing] = Vector()
scala> s match { case Nil => true ; case _ => false }
res0: Boolean = true
scala> s match { case x@Nil => true ; case _ => false }
res1: Boolean = true
scala> s match { case x@Nil => {x; true} ; case _ => false }
<console>:9: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
s match { case x@Nil => {x; true} ; case _ => false }
^
res2: Boolean = true |
@paulp said: scala> s match { case x@Nil => {x.::(""); true} ; case _ => false }
java.lang.ClassCastException: scala.collection.immutable.Vector cannot be cast to scala.collection.immutable.List
at .<init>(<console>:9)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>) That's a regression from -Xoldpatmat: scala> val s: Seq[Nothing] = Vector.empty
s: Seq[Nothing] = Vector()
scala> s match { case x@Nil => {x.::(""); true} ; case _ => false }
res0: Boolean = false There's a test ostensibly for #1503, but it's not a good test. |
@adriaanm said: (By the de facto semantics of a constant pattern, Thus |
@paulp said: |
@adriaanm said: We know that if this variable is used under this unsound assumption, the code will always fail at run-time. I don't see how this is going to break existing code that worked at run-time -- do we care about time bombs that type checked but could never work? Lest you think I'm being overly defensive, I'm reacting to https://issues.scala-lang.org/browse/SI-1503?focusedCommentId=43564&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-43564 |
@paulp said: None of that means we shouldn't fix it, and I don't have any reason to believe it's going to hit that many places in the wild, I'm just answering the question. If you're thinking on this matter, this would be a great time to look at the ticket I was bugging you about a month ago, #785. And at my implementation of much of what's in it, paulp/scala@4bd8ad6ae5 . |
@adriaanm said: case tpe : NoType.type =>
reifyMirrorObject(tpe)
case tpe : NoPrefix.type =>
reifyMirrorObject(tpe) Proposed patch: https://github.com/adriaanm/scala/commits/ticket-5024 I'm not sure we should do this in 2.10.1, but slightly in favor. |
@adriaanm said: |
@gkossakowski said: |
The pattern matcher strips unused bindings, which is good, but this alters the behavior w.r.t #1503, which is not so good. I need to record what bindings were stripped and type the RHS accordingly.
The text was updated successfully, but these errors were encountered: