8175317: javac does not issue unchecked warnings when checking method reference return types
authormcimadamore
Wed, 08 Mar 2017 14:21:13 +0000
changeset 44184 606c14ee20ed
parent 44183 17244500b154
child 44185 309b455e3ccc
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
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/lambda/T8175317.java
langtools/test/tools/javac/lambda/T8175317.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Mar 08 13:17:07 2017 +0530
+++ b/langtools/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/langtools/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/langtools/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