Skip to content

Commit

Permalink
Merge pull request scala#4670 from retronym/ticket/9422
Browse files Browse the repository at this point in the history
SI-9422 Fix incorrect constant propagation
  • Loading branch information
lrytz committed Jul 29, 2015
2 parents 65fa73d + ec95e53 commit a745f06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ abstract class ConstantOptimization extends SubComponent {
// out all the possibilities
case Impossible(possible2) => (possible -- possible2).nonEmpty
})
def mightNotEqual(other: Contents): Boolean = (this ne other) && (other match {
// two Possibles might not be equal if either has possible members that the other doesn't
case Possible(possible2) => (possible -- possible2).nonEmpty || (possible2 -- possible).nonEmpty
def mightNotEqual(other: Contents): Boolean = (other match {
case Possible(possible2) =>
// two Possibles must equal if each is known to be of the same, single value
val mustEqual = possible.size == 1 && possible == possible2
!mustEqual
case Impossible(_) => true
})
}
Expand Down
11 changes: 11 additions & 0 deletions test/files/run/t9422.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Test(val x: Long) {
def sameDirection(y: Long): Boolean =
(y == 0 || x == 0 || ((y > 0) == (x > 0)))
}

object Test {
def main(args: Array[String]) {
val b = new Test(1L)
assert(!b.sameDirection(-1L))
}
}

0 comments on commit a745f06

Please sign in to comment.