RFR: 8325805: Compiler Implementation for Flexible Constructor Bodies (Second Preview) [v5]

Jan Lahoda jlahoda at openjdk.org
Wed May 8 18:22:53 UTC 2024


On Wed, 8 May 2024 17:58:14 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 3778:
>> 
>>> 3776:                     if (staticOnly)
>>> 3777:                         sym = new StaticError(sym);
>>> 3778:                     else if (env1.info.ctorPrologue && sym.kind == VAR && !isAllowedInPrologue(env1, (VarSymbol)sym))
>> 
>> Question: why `sym.kind == VAR`? Can `sym` be something else then a variable here (given `name` can only be `this` or `super`, unless I am mistaken)?
>
> @lahodaj,
> 
> Thanks for your review.
> 
>> Can sym be something else then a variable here (given `name` can only be `this` or `super`)?
> 
> It's true that `name` can only be `this` or `super` - I've added an assertion to that effect in 887699b4085.
> 
> It's probably also true that `sym` has to be a `VarSymbol` but that was not immediately provable just from looking at the code. I've been burned before by making such assumptions (e.g., when things like `ResolveError` can sometimes pop up) so I'm playing it safe here.

I may be too strict, but: I don't see a realistic way how it could be some kind of an error symbol here (as this fetches the symbol from a `Scope`). I may be wrong. But unless there's a known/realistic way how the symbol could be something else than a VarSymbol, I think I would prefer the code to fail one way or another here, rather than continuing. Because when the execution will continue with in an unpredicted situation, we don't know what will happen.

But, as I say, it may be too strict.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18088#discussion_r1594458384


More information about the compiler-dev mailing list