Skip to content

Commit d1d5826

Browse files
committed
Remove JavaAnnotationArg context property§
1 parent d3f46fc commit d1d5826

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ object Typer {
8181
*/
8282
private val DroppedEmptyArgs = new Property.Key[Unit]
8383

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-
9384
/** An attachment that indicates a failed conversion or extension method
9485
* search was tried on a tree. This will in some cases be reported in error messages
9586
*/
@@ -863,14 +854,20 @@ class Typer extends Namer
863854
case _ => tree
864855
}
865856

857+
866858
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+
}
874871

875872
assignType(cpy.NamedArg(tree)(tree.name, arg1), arg1)
876873
}
@@ -1994,12 +1991,10 @@ class Typer extends Namer
19941991
def annotContext(mdef: untpd.Tree, sym: Symbol)(using Context): Context = {
19951992
def isInner(owner: Symbol) = owner == sym || sym.is(Param) && owner == sym.owner
19961993
val outer = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
1997-
val c = outer.property(ExprOwner) match {
1994+
outer.property(ExprOwner) match {
19981995
case Some(exprOwner) if outer.owner.isClass => outer.exprContext(mdef, exprOwner)
19991996
case _ => outer
20001997
}
2001-
if (c.isJava) c.fresh.setProperty(JavaAnnotationArg, ())
2002-
else c
20031998
}
20041999

20052000
def completeAnnotations(mdef: untpd.MemberDef, sym: Symbol)(using Context): Unit = {

0 commit comments

Comments
 (0)