diff options
author | Paul Phillips <paulp@improving.org> | 2010-06-08 02:15:50 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-06-08 02:15:50 +0000 |
commit | a1e29d20aa7b49caf07e7992287eb0ba8208558a (patch) | |
tree | fb1679e4a3e2c04d6b979d824900688e7e9ec920 | |
parent | caa6bf0e7a9c02b7519549c289f7a455bad281b1 (diff) | |
download | scala-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.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 12 | ||||
-rw-r--r-- | test/files/pos/bug3521/DoubleValue.java | 7 | ||||
-rw-r--r-- | test/files/pos/bug3521/a.scala | 4 |
4 files changed, 18 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 597a34c773..0d881e0068 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -214,7 +214,6 @@ trait Definitions extends reflect.generic.StandardDefinitions { def Array_length = getMember(ArrayClass, nme.length) lazy val Array_clone = getMember(ArrayClass, nme.clone_) lazy val ArrayModule = getModule("scala.Array") - def ArrayModule_apply = getMember(ArrayModule, nme.apply) // reflection / structural types lazy val SoftReferenceClass = getClass("java.lang.ref.SoftReference") 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 diff --git a/test/files/pos/bug3521/DoubleValue.java b/test/files/pos/bug3521/DoubleValue.java new file mode 100644 index 0000000000..e8c093890b --- /dev/null +++ b/test/files/pos/bug3521/DoubleValue.java @@ -0,0 +1,7 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface DoubleValue { + double value(); +}
\ No newline at end of file diff --git a/test/files/pos/bug3521/a.scala b/test/files/pos/bug3521/a.scala new file mode 100644 index 0000000000..94bb451fc3 --- /dev/null +++ b/test/files/pos/bug3521/a.scala @@ -0,0 +1,4 @@ +class Test { + @DoubleValue(-0.05) + var a = 0 +}
\ No newline at end of file |