Skip to content

Fix type NamedArg of annotations when pt is nullable #11974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,9 @@ class Typer extends Namer
* of annotation defined as `@interface Annot { int[] value() }`
* We assume that calling `typedNamedArg` in context of Java implies that we are dealing
* with annotation contructor, as named arguments are not allowed anywhere else in Java.
* Under explicit nulls, the pt could be nullable. We need to strip `Null` type first.
*/
val arg1 = pt match {
val arg1 = pt.stripNull match {
case AppliedType(a, typ :: Nil) if ctx.isJava && a.isRef(defn.ArrayClass) =>
tryAlternatively { typed(tree.arg, pt) } {
val elemTp = untpd.TypedSplice(TypeTree(typ))
Expand Down
7 changes: 7 additions & 0 deletions tests/explicit-nulls/pos/annotaions-args/JAnnots.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class JAnnots {
@SuppressWarnings("unused")
public void f1() {}

@SuppressWarnings({"unused"})
public void f2() {}
}
4 changes: 4 additions & 0 deletions tests/explicit-nulls/pos/annotaions-args/SAnnots.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SAnnots {
@SuppressWarnings(Array("unused"))
def f() = {}
}