changeset 653:ce46b6012362

Bug fixes: *) check that the compiler emits meaningful diagnostics when the lambda body contains bad statements *) the routine that checks for SAM types should skip defender methods in extended interfaces *) failure of regression test CheckExamples.java depending on localization settings
author mcimadamore
date Thu, 19 Aug 2010 13:11:51 +0100
parents c3232ad98c72
children 1bb5b46bb326
files src/share/classes/com/sun/tools/javac/code/Types.java src/share/classes/com/sun/tools/javac/parser/JavacParser.java test/tools/javac/diags/examples/IllegalChar.java test/tools/javac/lambda/BadStatementInLambda.java test/tools/javac/lambda/BadStatementInLambda.out test/tools/javac/lambda/Defender01.java
diffstat 6 files changed, 92 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Aug 16 11:00:44 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Aug 19 13:11:51 2010 +0100
@@ -490,6 +490,7 @@
             if (e.sym != null && 
                     e.sym.kind == Kinds.MTH &&
                     (e.sym.flags() & ABSTRACT) != 0 &&
+                    (e.sym.flags() & DEFENDER) == 0 &&
                     !overridesObjectMethod(e.sym, t.tsym)) {
                 if (buf.isEmpty() ||
                         (e.sym.name == buf.first().name &&
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Aug 16 11:00:44 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Aug 19 13:11:51 2010 +0100
@@ -1443,8 +1443,10 @@
             switch (sk) {
                 case STATEMENT: isBlock = true; break;
                 case EXPRESSION_STATEMENT:
+                case EXPRESSION:
                     parseExpression();
                     isBlock = S.token() != RBRACE;
+                    break;
             }
         }
         S.popState();
@@ -2160,7 +2162,7 @@
                     } else {
                         return isExpressionStatement(t) ?
                             StatementKind.EXPRESSION_STATEMENT :
-                            StatementKind.ERRONEOUS;
+                            StatementKind.EXPRESSION;
                     }
                 }
                 finally {
--- a/test/tools/javac/diags/examples/IllegalChar.java	Mon Aug 16 11:00:44 2010 +0100
+++ b/test/tools/javac/diags/examples/IllegalChar.java	Thu Aug 19 13:11:51 2010 +0100
@@ -24,5 +24,5 @@
 // key: compiler.err.illegal.char
 
 class IllegalChar {
-    int i = ¬;
+    int i = `;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/BadStatementInLambda.java	Thu Aug 19 13:11:51 2010 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2010, 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
+ * @summary check that the compiler emits meaningful diagnostics when the lambda body contains bad statements
+ * @author  Maurizio Cimadamore
+ * @compile/fail/ref=BadStatementInLambda.out -XDrawDiagnostics BadStatementInLambda.java
+ */
+
+class BadStatementInLambda {
+
+    interface SAM{
+        Object m();
+    }
+
+    SAM t1 = #{ null; };
+    SAM t2 = #{ 1; };
+    SAM t3 = #{ 1 + 5; };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/BadStatementInLambda.out	Thu Aug 19 13:11:51 2010 +0100
@@ -0,0 +1,4 @@
+BadStatementInLambda.java:37:17: compiler.err.not.stmt
+BadStatementInLambda.java:38:17: compiler.err.not.stmt
+BadStatementInLambda.java:39:19: compiler.err.not.stmt
+3 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/Defender01.java	Thu Aug 19 13:11:51 2010 +0100
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010, 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
+ * @summary routine that checks for SAM types should skip defender methods in extended interfaces
+ * @author  Maurizio Cimadamore
+ * @compile Defender01.java
+ */
+
+class Defender01 {
+
+    interface A{
+        Object m();
+        extension void n() default E.n;
+    }
+
+    static class E{
+        static void n(A a){};
+    }
+
+    A t = #{ null };
+}