diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 12 |
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 |