RFR: JDK-8243074: Misplaced and/or duplicate super or this constructor invocation not attributed

Jan Lahoda jan.lahoda at oracle.com
Fri Apr 17 15:27:17 UTC 2020


Hi,

Consider code like:
---
class Constructors extends BaseWithConstructor {
         Constructors(String name) {
             System.err.println();
             this(name.length());
             super(name.length());
             this(name.length());
         }
         Constructors(int i) {super(i);}
}
class BaseWithConstructor {
     BaseWithConstructor(int len) {}
}
---

Attr.visitApply will not attribute the this/super constructor 
invocations inside Constructors(String name), as it only attributes the 
first this/super constructor invocation (if any). As a result 
Trees.getElement (or Trees.getTypeMirror) will not return good results 
on AST node from inside these this/super constructor invocations.

The proposed solution is to attribute all super/this constructor 
invocations in Attr.visitApply. If the super/this constructor is 
misplaced, or duplicated, it will still get flagged as an error, but the 
AST will be enhanced with Symbols and Types.

Webrev:
http://cr.openjdk.java.net/~jlahoda/8243074/webrev.00/

JBS: https://bugs.openjdk.java.net/browse/JDK-8243074

How does this look?

Thanks,
     Jan


More information about the compiler-dev mailing list