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

6.3: Clarify that a nested declaration's scope includes component list of enclosing record class

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 19
    • 18
    • specification

      The legality of the following program depends on whether the scope of the simple name D is (i) just the RecordBody of C, not the RecordHeader `(D x)`; or (ii) the RecordBody of C _and_ the RecordHeader.

      record C(D x) {
          class D {}
      }

      If (i), then the record component `D x` is illegal (D not in scope).
      If (ii), then the record component is legal.

      The record component _should_ be legal because the program is specified by 8.10.3 to be equivalent to the following declaration of C, which is plainly legal:

      class C {
          private final D x = ...;
          public D x() { ... }
          class D {}
      }

      It's unreasonable to ask people to sketch out the equivalent program in order to figure scope. 6.3 should clarify that "The scope of a declaration of a member m declared in or inherited by a class or interface C (§8.2, §9.2) is the entire body of C, including any nested class or interface declarations. ***If C is a record class, then the scope of m additionally includes the header of the record declaration of C.***"

            gbierman Gavin Bierman
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: