I think the approach is right, the specific list of stuff might need to be reviewed more carefully (specifically, I've not thought through the connection with inner classes, which we've now opened the door to.)  Let's call it a placeholder and we'll make sure to review it more carefully after you've worked through the implementation and caught any obvious gaps?

On 2/7/2023 12:52 PM, Archie Cobbs wrote:
Ping to Brian...

Any thoughts or comments on the proposed description below for "pre-initialization context"?

I went ahead and added it into the JEP draft but am happy to adjust as needed.

Thanks,
-Archie

On Thu, Feb 2, 2023 at 3:49 PM Archie Cobbs <[email protected]> wrote:

    On Thu, Feb 2, 2023 at 2:16 PM Brian Goetz
    <[email protected]> wrote:

        This can be amended to:

        An explicit constructor invocation statement introduces an
        _pre-initialization context_, which limits the use of
        constructs that refer to the current object.  Notably, the
        keywords `this` and `super` are prohibited in a
        pre-initialization context, as are unqualified references to
        instance variables and instance methods of lexically enclosing
        declarations.


    That might not work. For example, this source is legal (as it
    should be) and yet the 'this' keyword appears within the super() call:

    $ cat Outer.java
    public class Outer {

        public int x;

        public Outer(int x) {
            this.x = x;
        }

        public class Inner extends Outer {
            public Inner() {
                super(Outer.this.x + 10);
            }
        }

        public static void main(String[] args) {
            System.out.println(new Outer(10).new Inner().x);
        }
    }
    $ java -cp classes Outer
    20

    What about something like this?

        An explicit constructor invocation statement introduces a
        /pre-initialization context/, which includes the prologue of
        the constructor and the explicit constructor invocation
        statement, and which prohibits the use of constructs that
        refer explicitly or implicitly to the current object. These
        include this or super referring to the current object,
        unqualified references to instance variables or instance
        methods of the current object, method references referring to
        instance methods of the current object, and instantiations of
        inner classes of the current object's class for which the
        current object is the enclosing instance (§8.1.3).

--
Archie L. Cobbs

Reply via email to