summaryrefslogtreecommitdiff
path: root/test/files/run/number-parsing.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-09-17 21:20:56 +0000
committerPaul Phillips <paulp@improving.org>2010-09-17 21:20:56 +0000
commit513fd181bc99263c92f759c4e17889dcb8da53f0 (patch)
tree1622666cd62bd160b68bc0205de6db4317c6026a /test/files/run/number-parsing.scala
parentab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9 (diff)
downloadscala-513fd181bc99263c92f759c4e17889dcb8da53f0.tar.gz
scala-513fd181bc99263c92f759c4e17889dcb8da53f0.tar.bz2
scala-513fd181bc99263c92f759c4e17889dcb8da53f0.zip
Restoring negative literal parsing behavior to ...
Restoring negative literal parsing behavior to what should be the least surprising option. Thanks much to Johannes Rudolph for identifying the bug in the bytecode generator which needed addressing for us to arrive at proper -0.0 behavior, and for writing the majority of this patch. A '-' followed immediately by either a number or a period should now always be treated as a single numeric literal, which means the minus binds more tightly than anything else. A specific example of how this differs from 2.8 final is: -5.+(10) == 5.0 // and not -15.0 The full range of potentially ambiguous parses involving prefix operators, numbers, and dots is quite large and still needs to be completely and clearly specified. Closes #2378 and #3657, review by odersky, jrudolph.
Diffstat (limited to 'test/files/run/number-parsing.scala')
-rw-r--r--test/files/run/number-parsing.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/number-parsing.scala b/test/files/run/number-parsing.scala
new file mode 100644
index 0000000000..ad1481063e
--- /dev/null
+++ b/test/files/run/number-parsing.scala
@@ -0,0 +1,31 @@
+object Test {
+ def numTests() = {
+ val MinusZero = Float.box(-0.0f)
+ val PlusZero = Float.box(0.0f)
+
+ assert(PlusZero match { case MinusZero => false ; case _ => true })
+ assert(MinusZero match { case PlusZero => false ; case _ => true })
+ assert((MinusZero: scala.Float) == (PlusZero: scala.Float))
+ assert(!(MinusZero equals PlusZero))
+
+ List(
+ -5f.max(2) ,
+ -5f max 2 ,
+ -5.max(2) ,
+ -5 max 2
+ ) foreach (num => assert(num == 2))
+ }
+
+ case class Foo(val x: Double) {
+ def unary_- : Foo = Foo(-x)
+ def +(other: Foo): Foo = Foo(x + other.x)
+ }
+ def objTests = {
+ assert(-Foo(5.0) + Foo(10.0) == Foo(5.0))
+ assert(-Foo(5.0).+(Foo(10.0)) == Foo(-15.0))
+ }
+
+ def main(args: Array[String]): Unit = {
+ numTests()
+ }
+}