Forward references in initializers

Dan Smith daniel.smith at oracle.com
Fri Nov 8 21:49:18 UTC 2024


On Nov 8, 2024, at 11:59 AM, Dan Smith <daniel.smith at oracle.com> wrote:

Conclusion: I think I'm happy with a DA/DU analysis that treats initializers as if they run in left-to-right order, before the start of the constructor. It's not really true, but it detects the errors we need to detect with less complexity.

Ugh, never mind, spoke too soon.

We have rules that say:
- All blank final instance fields must be DU before a 'this()' invocation occurs
- All blank strict instance fields must be DA before a 'super()' invocation occurs

These rules rely on a more nuanced analysis: the 'this()' rule assumes no initializers have run, while the 'super()' rule assumes early initializers have run. You only get those outcomes by modeling the assignments at the proper place where they will actually occur at run time, and excluding any initializers that won't run until after the invocation.

Plus the rules about assignments in the initializers and the prologue need to somehow pass information between each other to prevent multiple assignments.

So I think we'll have to stick with the early vs. late DA analysis, even though it works differently than the simpler left-to-right forward reference restriction. And this means DATest should be allowed.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-experts/attachments/20241108/514b1784/attachment-0001.htm>


More information about the valhalla-spec-experts mailing list