[lworld] RFR: Make "PrimitiveParameterizedClass.default" a poly expression. [v5]

Srikanth Adayapalam sadayapalam at openjdk.java.net
Mon Aug 2 11:44:49 UTC 2021


On Sun, 25 Jul 2021 21:14:57 GMT, Jesper Steen Møller <jespersm at openjdk.org> wrote:

>> Make .default a separate node type in the parser.
>> 
>> ## Issue
>> [JDK-8211914](https://bugs.openjdk.java.net/browse/JDK-8211914): [lworld] Javac should support type inference for default value creation
>> 
>> Note: The Linux x86 builds in GitHub actions seem to fail with something completely unrelated to these changes.
>
> Jesper Steen Møller has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Whitespace

Changes requested by sadayapalam (Committer).

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java line 284:

> 282:         if (applyTree != null) {
> 283:             return applyTree.arguments.isEmpty();
> 284:         } else {

The return statement is not reachable and so the block is not useful. This is because, Foo<>.default is a syntax error. Given a primitive class Foo<T> we will only support Foo.default involving implicit diamond like inference and will not support Foo<>.default which is what this code is handling.

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java line 287:

> 285:             // No type arguments before .default - Consider if the type is generic or not
> 286:             return clazztype == null || clazztype.tsym.type.isParameterized();
> 287:         }

This method is problematic - This will always treat Foo.default as a poly expression in an invocation context even when the concerned primitive type is not a generic class.  For instance the Foo.default expression in the following snippet becomes a poly expression when it is a standalone expression in reality:


primitive class X {

    static void foo(Object o) {
    }

    public static void main(String [] args) {
        foo(X.default);    
    }

}

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java line 295:

> 293:             case TYPEAPPLY: return (JCTypeApply)tree;
> 294:             case NEWCLASS: return getTypeApplication(((JCNewClass)tree).clazz);
> 295:             case ANNOTATED_TYPE: return getTypeApplication(((JCAnnotatedType)tree).underlyingType);

I think there is a copy + paste problem. We can never see a NEWCLASS here.  The LHS of .default is just a type node and cannot be an rvalue expression ==>  new X().default is illegal.

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

PR: https://git.openjdk.java.net/valhalla/pull/369


More information about the valhalla-dev mailing list