RFR: 8194743: Compiler implementation for Statements before super() [v14]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Sep 25 15:10:19 UTC 2023
On Mon, 25 Sep 2023 14:27:04 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
>> The kind is used in some other parts of Resolve to determine whether some errors should be skipped in some places, or recovered from. I'd advise against creating a new error kind, which might end up invalidating some existing check which depend on STATICERR. E.g.:
>>
>>
>> final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
>> return phase.ordinal() > maxPhase.ordinal() ||
>> !sym.kind.isResolutionError() || sym.kind == AMBIGUOUS || sym.kind == STATICERR;
>> }
>>
>>
>> E.g. you don't want overload resolution to try new candidates because you tried to call a method and you don't have a `this` - e.g. the compiler behavior should be similar as to when an instance method is called and no `this` is available (meaning: the found method is correct, and the error should be reported, no attempt should be made at recovery).
>
> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1336028332
More information about the compiler-dev
mailing list