changeset 52028:6601da9e0237 lworld

8210906: [lworld] default value creation should not impose raw types on users.
author sadayapalam
date Wed, 19 Sep 2018 12:07:21 +0530
parents d17f366ae373
children 142e4a2255f4
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/valhalla/lworld-values/ParameterizedDefault.java test/langtools/tools/javac/valhalla/lworld-values/UncheckedDefault.java test/langtools/tools/javac/valhalla/lworld-values/UncheckedDefault.out
diffstat 5 files changed, 76 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Sep 18 15:00:34 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Sep 19 12:07:21 2018 +0530
@@ -3711,9 +3711,7 @@
             if (warned) return; // suppress redundant diagnostics
             switch (lint) {
                 case UNCHECKED:
-                    JCTree tree;
-                    if (!(tree = pos().getTree()).hasTag(Tag.SELECT) || ((JCFieldAccess) tree).name != names._default)
-                        Check.this.warnUnchecked(pos(), Warnings.ProbFoundReq(diags.fragment(uncheckedKey), found, expected));
+                    Check.this.warnUnchecked(pos(), Warnings.ProbFoundReq(diags.fragment(uncheckedKey), found, expected));
                     break;
                 case VARARGS:
                     if (method != null &&
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Sep 18 15:00:34 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Sep 19 12:07:21 2018 +0530
@@ -1363,6 +1363,12 @@
                             t = toP(F.at(pos1).TypeApply(t, args.toList()));
                             while (token.kind == DOT) {
                                 nextToken();
+                                if (token.kind == DEFAULT) {
+                                    selectExprMode();
+                                    t = F.at(pos).Select(t, names._default);
+                                    nextToken();
+                                    return term3Rest(t, typeArgs);
+                                }
                                 selectTypeMode();
                                 t = toP(F.at(token.pos).Select(t, ident()));
                                 t = typeArgumentsOpt(t);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/ParameterizedDefault.java	Wed Sep 19 12:07:21 2018 +0530
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8210906
+ * @summary [lworld] default value creation should not impose raw types on users.
+ * @run main/othervm -XX:+EnableValhalla ParameterizedDefault
+ */
+
+public __ByValue class ParameterizedDefault<E> {
+    E value;
+    ParameterizedDefault(E value) { this.value = value; }
+    static String foo (Object p) {
+        return ("Object version");
+    }
+    static String foo (String p) {
+        return ("String version");
+    }
+    static String foo (java.util.Date p) {
+        return ("Date version");
+    }
+    public static void main(String [] args) {
+        var foo = ParameterizedDefault.default;
+        var soo = ParameterizedDefault<String>.default;
+        if (!foo(foo.value).equals("Object version") ||
+            !foo(soo.value).equals("String version") ||
+            !foo(ParameterizedDefault<java.util.Date>.default.value).equals("Date version"))
+            throw new AssertionError("Broken");
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/UncheckedDefault.java	Wed Sep 19 12:07:21 2018 +0530
@@ -0,0 +1,14 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8210906
+ * @summary [lworld] default value creation should not impose raw types on users.
+ * @compile/fail/ref=UncheckedDefault.out -Xlint:all -Werror -XDrawDiagnostics -XDdev UncheckedDefault.java
+ */
+
+public __ByValue class UncheckedDefault<E> {
+    E value;
+    UncheckedDefault(E value) { this.value = value; }
+    public static void main(String [] args) {
+        UncheckedDefault<String> foo = UncheckedDefault.default;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/UncheckedDefault.out	Wed Sep 19 12:07:21 2018 +0530
@@ -0,0 +1,4 @@
+UncheckedDefault.java:12:56: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), UncheckedDefault, UncheckedDefault<java.lang.String>
+- compiler.err.warnings.and.werror
+1 error
+1 warning
\ No newline at end of file