@@ -81,15 +81,6 @@ object Typer {
81
81
*/
82
82
private val DroppedEmptyArgs = new Property .Key [Unit ]
83
83
84
-
85
- /** Marker context property that indicates that typer is resolving types for arguments of
86
- * an annotation defined in Java. This means that value of any type T can appear in positions where
87
- * Array[T] is expected.
88
- * For example, both `@Annot(5)` and `@Annot({5, 6}) are viable calls of the constructor
89
- * of annotation defined as `@interface Annot { int[] value() }`
90
- */
91
- private [typer] val JavaAnnotationArg = Property .Key [Unit ]()
92
-
93
84
/** An attachment that indicates a failed conversion or extension method
94
85
* search was tried on a tree. This will in some cases be reported in error messages
95
86
*/
@@ -863,14 +854,20 @@ class Typer extends Namer
863
854
case _ => tree
864
855
}
865
856
857
+
866
858
def typedNamedArg (tree : untpd.NamedArg , pt : Type )(using Context ): NamedArg = {
867
- val arg1 = if (ctx.property(JavaAnnotationArg ).isDefined) {
868
- pt match {
869
- case AppliedType (a, typ :: Nil ) if (a.isRef(defn.ArrayClass )) =>
870
- tryAlternatively { typed(tree.arg, pt) } { typed(untpd.JavaSeqLiteral (tree.arg :: Nil , TypeTree (typ)), pt) }
871
- case _ => typed(tree.arg, pt)
872
- }
873
- } else typed(tree.arg, pt)
859
+ /* Special case for resolving types for arguments of an annotation defined in Java.
860
+ * It allows that value of any type T can appear in positions where Array[T] is expected.
861
+ * For example, both `@Annot(5)` and `@Annot({5, 6}) are viable calls of the constructor
862
+ * of annotation defined as `@interface Annot { int[] value() }`
863
+ * We assume that calling `typedNamedArg` in context of Java implies that we are dealing
864
+ * with annotation contructor, as named arguments are not allowed anywhere else in Java.
865
+ */
866
+ val arg1 = pt match {
867
+ case AppliedType (a, typ :: Nil ) if ctx.isJava && a.isRef(defn.ArrayClass ) =>
868
+ tryAlternatively { typed(tree.arg, pt) } { typed(untpd.JavaSeqLiteral (tree.arg :: Nil , TypeTree (typ)), pt) }
869
+ case _ => typed(tree.arg, pt)
870
+ }
874
871
875
872
assignType(cpy.NamedArg (tree)(tree.name, arg1), arg1)
876
873
}
@@ -1994,12 +1991,10 @@ class Typer extends Namer
1994
1991
def annotContext (mdef : untpd.Tree , sym : Symbol )(using Context ): Context = {
1995
1992
def isInner (owner : Symbol ) = owner == sym || sym.is(Param ) && owner == sym.owner
1996
1993
val outer = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
1997
- val c = outer.property(ExprOwner ) match {
1994
+ outer.property(ExprOwner ) match {
1998
1995
case Some (exprOwner) if outer.owner.isClass => outer.exprContext(mdef, exprOwner)
1999
1996
case _ => outer
2000
1997
}
2001
- if (c.isJava) c.fresh.setProperty(JavaAnnotationArg , ())
2002
- else c
2003
1998
}
2004
1999
2005
2000
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(using Context ): Unit = {
0 commit comments