diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 22 | ||||
-rw-r--r-- | test/files/pos/annotations.scala | 19 |
3 files changed, 35 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index 13f26412a3..9f2065f297 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -192,7 +192,7 @@ abstract class TreeGen mkTypeApply(value, tpe, (if (any) Any_asInstanceOf else Object_asInstanceOf)) def mkClassOf(tp: Type): Tree = - Literal(Constant(tp)) setType ClassType(tp) + Literal(Constant(tp)) setType ConstantType(Constant(tp))// ClassType(tp) def mkCheckInit(tree: Tree): Tree = { val tpe = diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2a8fcb8a68..e7410690a2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2640,15 +2640,23 @@ trait Typers { self: Analyzer => None } else Some(NestedAnnotArg(annInfo)) - // use of: object Array.apply[A <: AnyRef](args: A*): Array[A] = ... - // and object Array.apply(args: Int*): Array[Int] = ... (and similar) - case Apply(fun, members) => + // use of Array.apply[T: ClassManifest](xs: T*): Array[T] + // 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 && - pt.typeSymbol == ArrayClass && - !pt.typeArgs.isEmpty) - trees2ConstArg(members, pt.typeArgs.head) + typedFun.symbol.name == nme.apply) + pt match { + case TypeRef(_, sym, argts) if (sym == ArrayClass && !argts.isEmpty) => + trees2ConstArg(args, argts.head) + case _ => + // For classfile annotations, pt can only be T: + // BT = Int, .., String, Class[_], JavaAnnotClass + // T = BT | Array[BT] + // So an array literal as argument can only be valid if pt is Array[_] + error(tree.pos, "found array constant, expected argument of type "+ pt) + None + } else tryConst(tree, pt) diff --git a/test/files/pos/annotations.scala b/test/files/pos/annotations.scala index 5570701011..0819379d86 100644 --- a/test/files/pos/annotations.scala +++ b/test/files/pos/annotations.scala @@ -89,3 +89,22 @@ trait BeanF { def isG(): Boolean def setG(nb: Boolean): Unit } + + +class Ann3(arr: Array[String]) extends ClassfileAnnotation +class Ann4(i: Int) extends ClassfileAnnotation +class Ann5(value: Class[_]) extends ClassfileAnnotation + +object Test3 { + final val i = 1083 + final val cls = classOf[String] +} + +class Test4 { + @Ann3(arr = Array("dlkfj", "DSF")) + @Ann4(i = 2908) + @Ann4(i = Test3.i) + @Ann5(value = classOf[Int]) + @Ann5(Test3.cls) + def foo {} +} |