-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require named arguments for java defined annotations
- Loading branch information
1 parent
6c4eace
commit f915648
Showing
11 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- [E201] Syntax Error: tests/neg/i20554/Test.scala:3:12 --------------------------------------------------------------- | ||
3 |@Annotation(3, 4) // error // error | ||
| ^ | ||
| Named arguments are required for Java defined annotations | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| Starting from Scala 3.6.0, named arguments are required for Java defined annotations. | ||
| Java defined annotations don't have an exact constructor representation | ||
| and we previously relied on the order of the fields to create one. | ||
| One possible issue with this representation is the reordering of the fields. | ||
| Lets take the following example: | ||
| | ||
| public @interface Annotation { | ||
| int a() default 41; | ||
| int b() default 42; | ||
| } | ||
| | ||
| Reordering the fields is binary-compatible but it might affect the meaning of @Annotation(1) | ||
| | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E201] Syntax Error: tests/neg/i20554/Test.scala:3:15 --------------------------------------------------------------- | ||
3 |@Annotation(3, 4) // error // error | ||
| ^ | ||
| Named arguments are required for Java defined annotations | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| Starting from Scala 3.6.0, named arguments are required for Java defined annotations. | ||
| Java defined annotations don't have an exact constructor representation | ||
| and we previously relied on the order of the fields to create one. | ||
| One possible issue with this representation is the reordering of the fields. | ||
| Lets take the following example: | ||
| | ||
| public @interface Annotation { | ||
| int a() default 41; | ||
| int b() default 42; | ||
| } | ||
| | ||
| Reordering the fields is binary-compatible but it might affect the meaning of @Annotation(1) | ||
| | ||
--------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public @interface Annotation { | ||
int a() default 41; | ||
int b() default 42; | ||
int c() default 43; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//> using options -explain | ||
|
||
@Annotation(3, 4) // error // error | ||
class Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public @interface Annotation { | ||
int a() default 41; | ||
int b() default 42; | ||
int c() default 43; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public @interface Container { | ||
SimpleAnnotation[] value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import java.lang.annotation.Repeatable; | ||
|
||
@Repeatable(Container.class) | ||
public @interface SimpleAnnotation { | ||
int a() default 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
@Container(Array(new SimpleAnnotation(), new SimpleAnnotation(1), new SimpleAnnotation(a = 1))) | ||
@Annotation(a = 1, b = 2) | ||
class Test |