changeset 52234:2045f7495341 lworld

8212175: [lworld] Trouble creating an anonymous value class with diamond syntax
author sadayapalam
date Mon, 15 Oct 2018 16:40:22 +0530
parents eec1ec6cd903
children 1b7fae44af66
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/langtools/tools/javac/valhalla/lworld-values/AnonymousValue.java
diffstat 2 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Mon Oct 15 09:46:55 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Mon Oct 15 16:40:22 2018 +0530
@@ -2191,7 +2191,8 @@
         // or by virtue of being a member of a diamond inferred anonymous class. Latter case is to
         // be treated "as if as they were annotated" with @Override.
         boolean mustOverride = explicitOverride ||
-                (env.info.isAnonymousDiamond && !m.isConstructor() && !m.isPrivate());
+                (env.info.isAnonymousDiamond && !m.isConstructor() && !m.isPrivate() &&
+                        (!m.owner.isValue() || (tree.body.flags & SYNTHETIC) == 0));
         if (mustOverride && !isOverrider(m)) {
             DiagnosticPosition pos = tree.pos();
             for (JCAnnotation a : tree.getModifiers().annotations) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/AnonymousValue.java	Mon Oct 15 16:40:22 2018 +0530
@@ -0,0 +1,47 @@
+/*
+ * 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 8212175
+ * @summary Trouble creating an anonymous value class with diamond syntax
+ * @run main/othervm -XX:+EnableValhalla AnonymousValue
+ */
+
+import java.util.function.Function;
+
+public class AnonymousValue {
+	 static Function<String, String> capitalizer() {
+        return new value Function<>() {
+            int x = 10;
+			@Override
+			public String apply(String t) {
+				return t.toUpperCase();
+			}
+        };
+	 }
+     public static void main(String[] args) {
+		 if (!capitalizer().apply("blah").equals("BLAH"))
+            throw new AssertionError("Failed");
+	 }
+}
\ No newline at end of file