diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-07-29 10:45:52 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-07-29 10:45:52 +0200 |
commit | a745f06e35e070061348e95725afb0def8ca45de (patch) | |
tree | f4f328c8c68455276b8a322c8c46efe07f72e61e | |
parent | 65fa73dff3e15f2d01b18c0528ac2dad6fe8e517 (diff) | |
parent | ec95e534a213a6ea760aa31c507d122ce449890a (diff) | |
download | scala-a745f06e35e070061348e95725afb0def8ca45de.tar.gz scala-a745f06e35e070061348e95725afb0def8ca45de.tar.bz2 scala-a745f06e35e070061348e95725afb0def8ca45de.zip |
Merge pull request #4670 from retronym/ticket/9422
SI-9422 Fix incorrect constant propagation
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala | 8 | ||||
-rw-r--r-- | test/files/run/t9422.scala | 11 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala index 0e6ee76eb2..fb1799e092 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala @@ -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 }) } diff --git a/test/files/run/t9422.scala b/test/files/run/t9422.scala new file mode 100644 index 0000000000..5ca2e8daaa --- /dev/null +++ b/test/files/run/t9422.scala @@ -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)) + } +} |