forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assignment context does not reject widening p.c. and boxing
- Loading branch information
Showing
4 changed files
with
43 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* @test /nodynamiccopyright/ | ||
* @summary Assignment context does not reject widening p.c. and boxing | ||
* @compile/fail/ref=AssignmentBug.out -XDrawDiagnostics -XDshould-stop.at=FLOW AssignmentBug.java | ||
*/ | ||
public class AssignmentBug { | ||
|
||
void test() { | ||
Integer t = (byte) 0; // error, no widening p.c. from byte to int and boxing | ||
Short s = (byte) 0; // error, no widening p.c. from byte to short and boxing | ||
|
||
Byte B1 = (char)0; // ok, narrowing p.c. from char to byte and boxing when target is Byte | ||
Byte B2 = (short)0; // ok, narrowing p.c. from short to byte and boxing when target is Byte | ||
Character C1 = (short)0; // ok, narrowing p.c. from short to char and boxing when target is Character | ||
Short S1 = (int)0; // ok, narrowing p.c. from int to char and boxing to Short | ||
} | ||
|
||
void testWithSwitches() { | ||
Integer i = 42; | ||
var s1 = switch (i) { | ||
case (byte)0 -> true; // error | ||
default -> false; | ||
}; | ||
|
||
Short s = 42; | ||
var s2 = switch (s) { | ||
case (byte)0 -> true; // error | ||
default -> false; | ||
}; | ||
} | ||
} |
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 @@ | ||
AssignmentBug.java:9:21: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: byte, java.lang.Integer) | ||
AssignmentBug.java:10:19: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: byte, java.lang.Short) | ||
AssignmentBug.java:21:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: byte, java.lang.Integer) | ||
AssignmentBug.java:27:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: byte, java.lang.Short) | ||
4 errors |