summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-19 18:08:15 +0000
committerPaul Phillips <paulp@improving.org>2011-05-19 18:08:15 +0000
commitccceeeb179c4d60155b6c5c9a96c8497ce25398f (patch)
tree69ed00ab743146cb9a5f406e020b323b7c71acb6
parent63735b31ef24092bec5aa117e45ff582fab82dc8 (diff)
downloadscala-ccceeeb179c4d60155b6c5c9a96c8497ce25398f.tar.gz
scala-ccceeeb179c4d60155b6c5c9a96c8497ce25398f.tar.bz2
scala-ccceeeb179c4d60155b6c5c9a96c8497ce25398f.zip
Apparent assumption that Literal(0) would be ad...
Apparent assumption that Literal(0) would be adapted to Literal(0.0f) as necessary mercilessly invalidated. Fixed mkZero to account for all types explicitly. Closes #4617, no review.
-rw-r--r--src/compiler/scala/reflect/internal/TreeGen.scala22
-rw-r--r--test/files/run/bug4617.check1
-rw-r--r--test/files/run/bug4617.scala15
3 files changed, 30 insertions, 8 deletions
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala
index d2e09aeaca..faf793527e 100644
--- a/src/compiler/scala/reflect/internal/TreeGen.scala
+++ b/src/compiler/scala/reflect/internal/TreeGen.scala
@@ -206,14 +206,20 @@ abstract class TreeGen {
* which is appropriate to the given Type.
*/
def mkZero(tp: Type): Tree = {
- val sym = tp.typeSymbol
- val tree =
- if (sym == UnitClass) Literal(())
- else if (sym == BooleanClass) Literal(false)
- else if (isValueClass(sym)) Literal(0)
- else if (NullClass.tpe <:< tp) Literal(null: Any)
- else abort("Cannot determine zero for " + tp)
-
+ val tree = tp.typeSymbol match {
+ case UnitClass => Literal(())
+ case BooleanClass => Literal(false)
+ case FloatClass => Literal(0.0f)
+ case DoubleClass => Literal(0.0d)
+ case ByteClass => Literal(0.toByte)
+ case ShortClass => Literal(0.toShort)
+ case IntClass => Literal(0)
+ case LongClass => Literal(0L)
+ case CharClass => Literal(0.toChar)
+ case _ =>
+ if (NullClass.tpe <:< tp) Literal(null: Any)
+ else abort("Cannot determine zero for " + tp)
+ }
tree setType tp
}
diff --git a/test/files/run/bug4617.check b/test/files/run/bug4617.check
new file mode 100644
index 0000000000..6bbcce30eb
--- /dev/null
+++ b/test/files/run/bug4617.check
@@ -0,0 +1 @@
+Str 8.0
diff --git a/test/files/run/bug4617.scala b/test/files/run/bug4617.scala
new file mode 100644
index 0000000000..2fea5e29ec
--- /dev/null
+++ b/test/files/run/bug4617.scala
@@ -0,0 +1,15 @@
+object Test {
+ def f1 = new { def f { lazy val d = 0d } }
+ def f2 = {
+ lazy val d = 4D
+ lazy val f = 4f
+
+ def bar = "Str " + (d + f)
+ bar
+ }
+
+ def main(args: Array[String]): Unit = {
+ f1
+ println(f2)
+ }
+}