Skip to content

Commit 16776c8

Browse files
authored
Merge pull request #11974 from dotty-staging/fix-namedArg-nullable
Fix type NamedArg of annotations when pt is nullable
2 parents 0d2bb9e + b2a5ae5 commit 16776c8

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,9 @@ class Typer extends Namer
905905
* of annotation defined as `@interface Annot { int[] value() }`
906906
* We assume that calling `typedNamedArg` in context of Java implies that we are dealing
907907
* with annotation contructor, as named arguments are not allowed anywhere else in Java.
908+
* Under explicit nulls, the pt could be nullable. We need to strip `Null` type first.
908909
*/
909-
val arg1 = pt match {
910+
val arg1 = pt.stripNull match {
910911
case AppliedType(a, typ :: Nil) if ctx.isJava && a.isRef(defn.ArrayClass) =>
911912
tryAlternatively { typed(tree.arg, pt) } {
912913
val elemTp = untpd.TypedSplice(TypeTree(typ))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class JAnnots {
2+
@SuppressWarnings("unused")
3+
public void f1() {}
4+
5+
@SuppressWarnings({"unused"})
6+
public void f2() {}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class SAnnots {
2+
@SuppressWarnings(Array("unused"))
3+
def f() = {}
4+
}

0 commit comments

Comments
 (0)