summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-06-08 02:15:50 +0000
committerPaul Phillips <paulp@improving.org>2010-06-08 02:15:50 +0000
commita1e29d20aa7b49caf07e7992287eb0ba8208558a (patch)
treefb1679e4a3e2c04d6b979d824900688e7e9ec920 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parentcaa6bf0e7a9c02b7519549c289f7a455bad281b1 (diff)
downloadscala-a1e29d20aa7b49caf07e7992287eb0ba8208558a.tar.gz
scala-a1e29d20aa7b49caf07e7992287eb0ba8208558a.tar.bz2
scala-a1e29d20aa7b49caf07e7992287eb0ba8208558a.zip
Taking another shot at negative constants as an...
Taking another shot at negative constants as annotation arguments since r22175 didn't quite get there. I call into the constant folder with the unfolded tree at the last point before it's going to fail the compile anyway. Closes #3521, review by odersky.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a892ae1582..fa5d693b1c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2522,7 +2522,10 @@ trait Typers { self: Analyzer =>
annotationError
}
- def tryConst(tr: Tree, pt: Type) = typed(tr, EXPRmode, pt) match {
+ /** Calling constfold right here is necessary because some trees (negated
+ * floats and literals in particular) are not yet folded.
+ */
+ def tryConst(tr: Tree, pt: Type) = typed(constfold(tr), EXPRmode, pt) match {
// null cannot be used as constant value for classfile annotations
case l @ Literal(c) if !(l.isErroneous || c.value == null) =>
Some(LiteralAnnotArg(c))
@@ -2547,11 +2550,10 @@ trait Typers { self: Analyzer =>
// and Array.apply(x: Int, xs: Int*): Array[Int] (and similar)
case Apply(fun, args) =>
val typedFun = typed(fun, funMode(mode), WildcardType)
- if (typedFun.symbol.owner == ArrayModule.moduleClass &&
- typedFun.symbol.name == nme.apply)
+ if (typedFun.symbol.owner == ArrayModule.moduleClass && typedFun.symbol.name == nme.apply)
pt match {
- case TypeRef(_, sym, argts) if (sym == ArrayClass && !argts.isEmpty) =>
- trees2ConstArg(args, argts.head)
+ case TypeRef(_, ArrayClass, targ :: _) =>
+ trees2ConstArg(args, targ)
case _ =>
// For classfile annotations, pt can only be T:
// BT = Int, .., String, Class[_], JavaAnnotClass