Skip to content

Commit 4fd41f7

Browse files
committed
Make sure all arguments to Java annot constructors are NamedArg's.
The Java model of annotations is unordered and name-based. Even though we typecheck things from source with a particular ordering, semantically we must always use `NamedArg`s to match the Java model.
1 parent 27a3f80 commit 4fd41f7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,17 @@ trait Applications extends Compatibility {
945945
val app1 =
946946
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
947947
else {
948-
if !sameSeq(args, orderedArgs)
949-
&& !isJavaAnnotConstr(methRef.symbol)
950-
&& !typedArgs.forall(isSafeArg)
951-
then
948+
if isJavaAnnotConstr(methRef.symbol) then
949+
// #19951 Make sure all arguments are NamedArgs for Java annotations
950+
if typedArgs.exists(!_.isInstanceOf[NamedArg]) then
951+
typedArgs = typedArgs.lazyZip(methType.asInstanceOf[MethodType].paramNames).map {
952+
case (arg: NamedArg, _) => arg
953+
case (arg, name) => NamedArg(name, arg)
954+
}
955+
else if !sameSeq(args, orderedArgs) && !typedArgs.forall(isSafeArg) then
952956
// need to lift arguments to maintain evaluation order in the
953957
// presence of argument reorderings.
958+
// (never do this for Java annotation constructors, hence the 'else if')
954959

955960
liftFun()
956961

0 commit comments

Comments
 (0)