Details
-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b24
Description
Based on the latest draft spec, the compiler should fail in two cases mentioned in the following assertion:
Chapter 14: Blocks, Statements, and Patterns
14.4 Local Variable Declarations
Assertion:
It is a compile-time error if a local variable declaration that does not include an Identifier and does not have an initializer is used in the following locations:
* a local variable declaration statement in a block (14.4.2)
* the header of a basic for statement (14.14.1)
However, the following code where an underscore is used without an intitializer compiles without any failures:
{
int _;
int x1 = 1, _, x2;
}
for (int x = 1, _; x<=1; x++) {
}
java -version
java version "21-internal" 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev)
Java HotSpot(TM) 64-Bit Server VM (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev, mixed mode, sharing)
Chapter 14: Blocks, Statements, and Patterns
14.4 Local Variable Declarations
Assertion:
It is a compile-time error if a local variable declaration that does not include an Identifier and does not have an initializer is used in the following locations:
* a local variable declaration statement in a block (14.4.2)
* the header of a basic for statement (14.14.1)
However, the following code where an underscore is used without an intitializer compiles without any failures:
{
int _;
int x1 = 1, _, x2;
}
for (int x = 1, _; x<=1; x++) {
}
java -version
java version "21-internal" 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev)
Java HotSpot(TM) 64-Bit Server VM (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev, mixed mode, sharing)