summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2010-02-10 14:48:58 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2010-02-10 14:48:58 +0000
commita165920200847b9aa336786dffc5d33ce5b86ab8 (patch)
treea55a3412c6aedaadbcbb8474e0d9382cca675bd0 /src
parent96a7efb1fd7db67c21ff5000d343765c925a83d7 (diff)
downloadscala-a165920200847b9aa336786dffc5d33ce5b86ab8.tar.gz
scala-a165920200847b9aa336786dffc5d33ce5b86ab8.tar.bz2
scala-a165920200847b9aa336786dffc5d33ce5b86ab8.zip
close #2984. review by community.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 53970fc873..879dadcbed 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2601,9 +2601,14 @@ trait Typers { self: Analyzer =>
hasError = true
annotationError
}
- def needConst(tr: Tree): None.type = {
- error(tr.pos, "annotation argument needs to be a constant; found: "+tr)
- None
+
+ def tryConst(tr: Tree, pt: Type) = typed(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))
+ case _ =>
+ error(tr.pos, "annotation argument needs to be a constant; found: "+tr)
+ None
}
/** Converts an untyped tree to a ClassfileAnnotArg. If the conversion fails,
@@ -2628,17 +2633,12 @@ trait Typers { self: Analyzer =>
!pt.typeArgs.isEmpty)
trees2ConstArg(members, pt.typeArgs.head)
else
- needConst(tree)
+ tryConst(tree, pt)
case Typed(t, _) => tree2ConstArg(t, pt)
- case tree => typed(tree, 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))
- case _ =>
- needConst(tree)
- }
+ case tree =>
+ tryConst(tree, pt)
}
def trees2ConstArg(trees: List[Tree], pt: Type): Option[ArrayAnnotArg] = {
val args = trees.map(tree2ConstArg(_, pt))