OpenJDK / lambda / lambda / langtools
changeset 1470:a78999ebabfc
Bug fixes:
*) recovery of speculative types fails if receiver is erroneous
*) static initializer in legacy interface classfiles cause spurious default method diagnostics
author | mcimadamore |
---|---|
date | Mon, 15 Oct 2012 13:52:13 +0100 |
parents | 966d32b093db |
children | 3b38d0120298 |
files | src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/jvm/ClassReader.java test/tools/javac/defender/crossCompile/Clinit.java test/tools/javac/defender/crossCompile/CrossCompile.java test/tools/javac/lambda/BadRecovery.java test/tools/javac/lambda/BadRecovery.out |
diffstat | 6 files changed, 114 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 12 11:43:27 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Oct 15 13:52:13 2012 +0100 @@ -3156,15 +3156,17 @@ * @param env The current environment. * @param resultInfo The expected result */ + @SuppressWarnings("fallthrough") Type checkId(JCTree tree, Type site, Symbol sym, Env<AttrContext> env, ResultInfo resultInfo, boolean useVarargs) { - Type pt = resultInfo.pt.tag == FORALL || resultInfo.pt.tag == METHOD ? - resultInfo.pt.map(deferredAttr.new SpeculativeDeferredTypeMap(sym, env.info.pendingResolutionPhase)) : - resultInfo.pt; + Type pt = (resultInfo.pt.tag == FORALL || resultInfo.pt.tag == METHOD) && + !site.isErroneous() ? + resultInfo.pt.map(deferredAttr.new SpeculativeDeferredTypeMap(sym, env.info.pendingResolutionPhase)) : + resultInfo.pt; if (pt.isErroneous()) { recoveryAttribArgs(env, resultInfo, sym); @@ -3250,8 +3252,9 @@ resultInfo.pt.getTypeArguments()); break; } - case PCK: case ERR: + case ERR: recoveryAttribArgs(env, resultInfo, sym); + case PCK: owntype = sym.type; break; default:
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Fri Oct 12 11:43:27 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon Oct 15 13:52:13 2012 +0100 @@ -1730,7 +1730,7 @@ Name name = readName(nextChar()); Type type = readType(nextChar()); if (currentOwner.isInterface() && - (flags & ABSTRACT) == 0) { + (flags & ABSTRACT) == 0 && !name.equals(names.clinit)) { if (majorVersion > Target.JDK1_8.majorVersion || (majorVersion == Target.JDK1_8.majorVersion && minorVersion >= Target.JDK1_8.minorVersion)) { currentOwner.flags_field |= DEFENDER;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/crossCompile/Clinit.java Mon Oct 15 13:52:13 2012 +0100 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012, 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. + */ +interface Clinit { + String s = Inner.m(); + + static class Inner { + static String m() { return ""; } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/crossCompile/CrossCompile.java Mon Oct 15 13:52:13 2012 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 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 clinit in interface doesn't cause spurious default method diagnostics + * @compile -source 1.4 -target 1.4 Clinit.java + * @compile CrossCompile.java + */ +class CrossCompile { + void test() { + String s = Clinit.s; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/BadRecovery.java Mon Oct 15 13:52:13 2012 +0100 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, 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 recovery of speculative types is not attempted if receiver is erroneous + * @compile/fail/ref=BadRecovery.out -XDrawDiagnostics BadRecovery.java + */ +class BadRecovery { + + interface SAM1 { + void m(Object o); + } + + void m(SAM1 m) { }; + + void test() { + m((receiver, t) -> { receiver.someMemberOfReceiver(()->{ Object x = f; }); }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/BadRecovery.out Mon Oct 15 13:52:13 2012 +0100 @@ -0,0 +1,3 @@ +BadRecovery.java:38:9: compiler.err.cant.apply.symbol.1: kindname.method, m, BadRecovery.SAM1, compiler.misc.type.lambda, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.incompatible.arg.types.in.lambda)) +BadRecovery.java:38:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null) +2 errors