-
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 ae3e2f4
Showing
15 changed files
with
160 additions
and
9 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-a/Test.scala:3:12 ------------------------------------------------------------- | ||
3 |@Annotation(3, 4) // error // error : Java defined annotation should be called with named arguments | ||
| ^ | ||
| 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-a/Test.scala:3:15 ------------------------------------------------------------- | ||
3 |@Annotation(3, 4) // error // error : Java defined annotation should be called with named arguments | ||
| ^ | ||
| 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,4 @@ | ||
public @interface Annotation { | ||
int a() default 41; | ||
int b() default 42; | ||
} |
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 : Java defined annotation should be called with named arguments | ||
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,21 @@ | ||
-- [E201] Syntax Error: tests/neg/i20554-b/Test.scala:3:18 ------------------------------------------------------------- | ||
3 |@SimpleAnnotation(1) // error: the parameters is not named 'value' | ||
| ^ | ||
| 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,4 @@ | ||
|
||
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 @@ | ||
//> using options -explain | ||
|
||
@SimpleAnnotation(1) // error: the parameters is not named 'value' | ||
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 @@ | ||
|
||
@Annotation(a = 1, b = 2) | ||
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,9 @@ | ||
|
||
public @interface SimpleAnnotation { | ||
|
||
int a() default 0; | ||
|
||
int value() default 1; | ||
|
||
int b() default 0; | ||
} |
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 @@ | ||
|
||
@SimpleAnnotation(1) // works because of the presence of a field called value | ||
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 @@ | ||
|
||
class MyAnnotation(a: Int, b: Int) extends annotation.StaticAnnotation | ||
|
||
@MyAnnotation(1, 2) // don't require named arguments as it is Scala Defined | ||
class Test |