提交 07c326db 编写于 作者: V vromero

8024809: javac, some lambda programs are rejected by flow analysis

Reviewed-by: jjg, dlsmith
上级 14f41e5b
......@@ -314,9 +314,6 @@ public class Attr extends JCTree.Visitor {
case CLASSDEF:
//class def is always an owner
return ((JCClassDecl)env.tree).sym;
case LAMBDA:
//a lambda is an owner - return a fresh synthetic method symbol
return new MethodSymbol(0, names.empty, null, syms.methodClass);
case BLOCK:
//static/instance init blocks are owner
Symbol blockSym = env.info.scope.owner;
......
......@@ -32,7 +32,7 @@ class T8016081 {
interface fint { int get(); }
@interface atype {
fint fld = ()->( fld == null ?0 : 1);
fint fld = ()->1;
}
@atype class T {}
......
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2013, 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
......@@ -26,13 +26,14 @@
* @bug 8003280
* @summary Add lambda tests
* check that recursive lambda (through field ref) is accepted in all contexts
* but field initialization
* @compile LambdaExpr13.java
*/
class LambdaExpr13 {
Runnable ir = () -> { ir.run(); };;
static Runnable sr = () -> { sr.run(); };
Runnable ir;
static Runnable sr;
{ ir = () -> { ir.run(); }; }
static { sr = () -> { sr.run(); }; }
......
/*
* Copyright (c) 2013, 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 8024809
* @summary javac, some lambda programs are rejected by flow analysis
* @compile/fail/ref=SelfInitializerInLambdaTesta.out -XDrawDiagnostics SelfInitializerInLambdaTesta.java
*/
public class SelfInitializerInLambdaTesta {
final Runnable r1 = ()->System.out.println(r1);
final Object lock = new Object();
final Runnable r2 = ()->{
System.out.println(r2);
synchronized (lock){}
};
final Runnable r3 = ()->{
synchronized (lock){
System.out.println(r3);
}
};
final Runnable r4 = ()->{
System.out.println(r4);
};
interface SAM {
int m(String s);
}
final SAM s1 = (String s)->{
System.out.println(s + s1.toString());
return 0;
};
final SAM s2 = (s)->{
System.out.println(s + s2.toString());
return 0;
};
}
SelfInitializerInLambdaTesta.java:33:48: compiler.err.illegal.self.ref
SelfInitializerInLambdaTesta.java:38:28: compiler.err.illegal.self.ref
SelfInitializerInLambdaTesta.java:44:32: compiler.err.illegal.self.ref
SelfInitializerInLambdaTesta.java:49:28: compiler.err.illegal.self.ref
SelfInitializerInLambdaTesta.java:57:32: compiler.err.illegal.self.ref
SelfInitializerInLambdaTesta.java:62:32: compiler.err.illegal.self.ref
6 errors
/*
* Copyright (c) 2013, 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 8024809
* @summary javac, some lambda programs are rejected by flow analysis
* @compile/fail/ref=SelfInitializerInLambdaTestb.out -XDrawDiagnostics SelfInitializerInLambdaTestb.java
*/
public class SelfInitializerInLambdaTestb {
final Runnable r1;
final Runnable r2 = ()-> System.out.println(r1);
SelfInitializerInLambdaTestb() {
r1 = ()->System.out.println(r1);
}
}
SelfInitializerInLambdaTestb.java:35:49: compiler.err.var.might.not.have.been.initialized: r1
SelfInitializerInLambdaTestb.java:38:37: compiler.err.var.might.not.have.been.initialized: r1
2 errors
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2013, 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
......@@ -29,7 +29,6 @@
* consistently w.r.t. local inner classes
*/
import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
......@@ -38,6 +37,7 @@ import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import com.sun.source.util.JavacTask;
public class TestSelfRef {
......@@ -176,10 +176,16 @@ public class TestSelfRef {
check();
}
void check() {
boolean isErrorExpected() {
//illegal forward ref
boolean errorExpected = ik.inMethodContext(sk) &&
(rk.selfRef || rk.forwardRef);
boolean result = ik.inMethodContext(sk) && (rk.selfRef || rk.forwardRef);
result |= (rk == RefKind.SELF_LAMBDA || rk == RefKind.FORWARD_LAMBDA);
return result;
}
void check() {
checkCount++;
boolean errorExpected = isErrorExpected();
if (diagChecker.errorFound != errorExpected) {
throw new Error("invalid diagnostics for source:\n" +
source.getCharContent(true) +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册