RFR: 8194743: Compiler implementation for Statements before super() [v14]

Archie Cobbs acobbs at openjdk.org
Mon Sep 25 16:04:12 UTC 2023


On Mon, 25 Sep 2023 15:06:57 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> OK got it. So what if we did this instead?
>> 
>> diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> index 295bb192a42..4c7c177163f 100644
>> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> @@ -4576,7 +4587,11 @@ JCDiagnostic inaccessiblePackageReason(Env<AttrContext> env, PackageSymbol sym)
>>      class StaticError extends InvalidSymbolError {
>>  
>>          StaticError(Symbol sym) {
>> -            super(STATICERR, sym, "static error");
>> +            this(sym, "static error");
>> +        }
>> +
>> +        StaticError(Symbol sym, String debugName) {
>> +            super(STATICERR, sym, debugName);
>>          }
>>  
>>          @Override
>> @@ -4595,6 +4610,32 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
>>          }
>>      }
>>  
>> +    /**
>> +     * Specialization of {@link InvalidSymbolError} for illegal
>> +     * early accesses within a constructor prologue.
>> +     */
>> +    class RefBeforeCtorCalledError extends StaticError {
>> +
>> +        RefBeforeCtorCalledError(Symbol sym) {
>> +            super(sym, "prologue error");
>> +        }
>> +
>> +        @Override
>> +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
>> +                DiagnosticPosition pos,
>> +                Symbol location,
>> +                Type site,
>> +                Name name,
>> +                List<Type> argtypes,
>> +                List<Type> typeargtypes) {
>> +            Symbol errSym = ((sym.kind == TYP && sym.type.hasTag(CLASS))
>> +                ? types.erasure(sym.type).tsym
>> +                : sym);
>> +            return diags.create(dkind, log.currentSource(), pos,
>> +                    "cant.ref.before.ctor.called", errSym);
>> +        }
>> +    }
>> +
>>      /**
>>       * InvalidSymbolError error class indicating that a pair of symbols
>>       * (either methods, constructors or operands) are ambiguous
>> @@ -4708,7 +4749,7 @@ class BadMethodReferenceError extends StaticError {
>>          boolean unboundLookup;
>>  
>>          public BadMethodReferenceError(Symbol sym, boolean unboundLookup) {
>> -            super(sym);
>> +            super(sym, "bad method ref error");
>>              this.unboundLookup = unboundLookup;
>>          }
>
> Yes, I think that is what I was referring to. Thanks for the patience.

Great - fixed in 3e75e19e230. Thanks for the mini-lesson :)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1336094981


More information about the compiler-dev mailing list