1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/BadReturn.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,38 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8003280 1.7 + * @summary Add lambda tests 1.8 + * check that incompatible return types in lambdas are flagged with error 1.9 + * @author Maurizio Cimadamore 1.10 + * @compile/fail/ref=BadReturn.out -XDrawDiagnostics BadReturn.java 1.11 + */ 1.12 + 1.13 +class BadReturn { 1.14 + 1.15 + interface SAM { 1.16 + Comparable<?> m(); 1.17 + } 1.18 + 1.19 + static void testNeg1() { 1.20 + SAM s = ()-> { 1.21 + if (true) { 1.22 + return ""; 1.23 + } else { 1.24 + return System.out.println(""); 1.25 + }}; 1.26 + } 1.27 + 1.28 + static void testNeg2() { 1.29 + SAM s = ()-> { return System.out.println(""); }; 1.30 + } 1.31 + 1.32 + static void testPos() { 1.33 + SAM s = ()-> { 1.34 + if (false) { 1.35 + return 10; 1.36 + } 1.37 + else { 1.38 + return true; 1.39 + }}; 1.40 + } 1.41 +}