changeset 4027:d8aeea31f9b5

8175317: javac does not issue unchecked warnings when checking method reference return types Summary: Missing Warner object on method reference return type check Reviewed-by: vromero
author mcimadamore
date Wed, 08 Mar 2017 14:21:13 +0000
parents 0873c6b6d28f
children 1d3c7096b3b6
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/lambda/T8175317.java test/tools/javac/lambda/T8175317.out
diffstat 3 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Mar 08 13:17:07 2017 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Mar 08 14:21:13 2017 +0000
@@ -3058,7 +3058,8 @@
 
         if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) {
             if (resType.isErroneous() ||
-                    new FunctionalReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) {
+                    new FunctionalReturnContext(checkContext).compatible(resType, returnType,
+                            checkContext.checkWarner(tree, resType, returnType))) {
                 incompatibleReturnType = null;
             }
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8175317.java	Wed Mar 08 14:21:13 2017 +0000
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8175317
+ * @summary javac does not issue unchecked warnings when checking method reference return types
+ * @compile/fail/ref=T8175317.out -Werror -Xlint:unchecked -XDrawDiagnostics T8175317.java
+ */
+
+import java.util.function.*;
+import java.util.*;
+
+class T8175317 {
+    void m(Supplier<List<String>> s) { }
+
+    void testMethodLambda(List l) {
+        m(() -> l);
+    }
+
+    void testAssignLambda(List l) {
+        Supplier<List<String>> s = () -> l;
+    }
+
+    void testMethodMref() {
+        m(this::g);
+    }
+
+    void testAssignMref() {
+        Supplier<List<String>> s = this::g;
+    }
+
+    List g() { return null; }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8175317.out	Wed Mar 08 14:21:13 2017 +0000
@@ -0,0 +1,7 @@
+T8175317.java:15:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, java.util.function.Supplier<java.util.List<java.lang.String>>, java.util.function.Supplier<java.util.List<java.lang.String>>, kindname.class, T8175317
+T8175317.java:19:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.List, java.util.List<java.lang.String>
+T8175317.java:23:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, java.util.function.Supplier<java.util.List<java.lang.String>>, java.util.function.Supplier<java.util.List<java.lang.String>>, kindname.class, T8175317
+T8175317.java:27:36: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.List, java.util.List<java.lang.String>
+- compiler.err.warnings.and.werror
+1 error
+4 warnings