Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308312

Compiler should fail when a local variable declaration does not include an Identifier and does not have an initializer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • None
    • tools
    • b24

      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)

            abimpoudis Angelos Bimpoudis
            ymaslyanko Yuriy Maslyanko
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: