mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 20:44:41 +02:00
8003280: Add lambda tests
Turn on lambda expression, method reference and default method support Reviewed-by: jjg
This commit is contained in:
parent
c39f1d99b4
commit
a494f0ab86
451 changed files with 15433 additions and 488 deletions
|
@ -27,8 +27,8 @@
|
|||
* @summary Conditional operator applies assignment conversion
|
||||
* @author Tim Hanson, BEA
|
||||
*
|
||||
* @compile -XDallowPoly Conditional.java
|
||||
* @compile/fail Conditional.java
|
||||
* @compile Conditional.java
|
||||
* @compile/fail -source 7 Conditional.java
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that default methods don't cause ClassReader to complete classes recursively
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods pkg/Foo.java
|
||||
* @compile pkg/Foo.java
|
||||
* @compile ClassReaderTest.java
|
||||
*/
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary negative test for ambiguous defaults
|
||||
* @compile/fail/ref=Neg01.out -XDallowDefaultMethods -XDrawDiagnostics Neg01.java
|
||||
* @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java
|
||||
*/
|
||||
|
||||
class Neg01 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that ill-formed MI hierarchies do not compile
|
||||
* @compile/fail/ref=Neg02.out -XDallowDefaultMethods -XDrawDiagnostics Neg02.java
|
||||
* @compile/fail/ref=Neg02.out -XDrawDiagnostics Neg02.java
|
||||
*/
|
||||
|
||||
class Neg02 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that re-abstraction works properly
|
||||
* @compile/fail/ref=Neg03.out -XDallowDefaultMethods -XDrawDiagnostics Neg03.java
|
||||
* @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java
|
||||
*/
|
||||
|
||||
class Neg03 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default method must have most specific return type
|
||||
* @compile/fail/ref=Neg04.out -XDallowDefaultMethods -XDrawDiagnostics Neg04.java
|
||||
* @compile/fail/ref=Neg04.out -XDrawDiagnostics Neg04.java
|
||||
*/
|
||||
|
||||
class Neg04 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that abstract methods are compatible with inherited defaults
|
||||
* @compile/fail/ref=Neg05.out -XDallowDefaultMethods -XDrawDiagnostics Neg05.java
|
||||
* @compile/fail/ref=Neg05.out -XDrawDiagnostics Neg05.java
|
||||
*/
|
||||
|
||||
class Neg05 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary flow analysis is not run on inlined default bodies
|
||||
* @compile/fail/ref=Neg06.out -XDallowDefaultMethods -XDrawDiagnostics Neg06.java
|
||||
* @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java
|
||||
*/
|
||||
|
||||
class Neg06 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default overrides are properly type-checked
|
||||
* @compile/fail/ref=Neg07.out -XDallowDefaultMethods -XDrawDiagnostics Neg07.java
|
||||
* @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java
|
||||
*/
|
||||
|
||||
class Neg07 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default overrides are properly type-checked
|
||||
* @compile/fail/ref=Neg08.out -XDallowDefaultMethods -XDrawDiagnostics Neg08.java
|
||||
* @compile/fail/ref=Neg08.out -XDrawDiagnostics Neg08.java
|
||||
*/
|
||||
class Neg08 {
|
||||
interface I {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default overrides are properly type-checked
|
||||
* @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg09.java
|
||||
* @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg09.java
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default overrides are properly type-checked
|
||||
* @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg10.java
|
||||
* @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg10.java
|
||||
*/
|
||||
class Neg10 {
|
||||
interface I<X extends Exception> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default overrides are properly type-checked
|
||||
* @compile/fail/ref=Neg11.out -XDallowDefaultMethods -XDrawDiagnostics Neg11.java
|
||||
* @compile/fail/ref=Neg11.out -XDrawDiagnostics Neg11.java
|
||||
*/
|
||||
class Neg11 {
|
||||
interface I {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that abstract methods are discarded in overload resolution diags
|
||||
* @compile/fail/ref=Neg12.out -XDallowDefaultMethods -XDrawDiagnostics Neg12.java
|
||||
* @compile/fail/ref=Neg12.out -XDrawDiagnostics Neg12.java
|
||||
*/
|
||||
class Neg12 {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2
|
||||
Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, ,{(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch))}
|
||||
Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, compiler.misc.no.args,{(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch))}
|
||||
Neg12.java:25:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Integer, compiler.misc.no.args, kindname.class, Neg12.B, (compiler.misc.arg.length.mismatch)
|
||||
3 errors
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that default method overriding object members are flagged as error
|
||||
* @compile/fail/ref=Neg13.out -XDallowDefaultMethods -XDrawDiagnostics Neg13.java
|
||||
* @compile/fail/ref=Neg13.out -XDrawDiagnostics Neg13.java
|
||||
*/
|
||||
interface Neg13 {
|
||||
default protected Object clone() { return null; } //protected not allowed here
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that a class cannot have two sibling interfaces with a default and abstract method
|
||||
* @compile/fail/ref=Neg14.out -XDallowDefaultMethods -XDrawDiagnostics Neg14.java
|
||||
* @compile/fail/ref=Neg14.out -XDrawDiagnostics Neg14.java
|
||||
*/
|
||||
class Neg14 {
|
||||
interface IA { int m(); }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that level skipping in default super calls is correctly rejected
|
||||
* @compile/fail/ref=Neg15.out -XDallowDefaultMethods -XDrawDiagnostics Neg15.java
|
||||
* @compile/fail/ref=Neg15.out -XDrawDiagnostics Neg15.java
|
||||
*/
|
||||
class Neg15 {
|
||||
interface I { default void m() { } }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary check that level skipping in default super calls is correctly rejected
|
||||
* @compile/fail/ref=Neg16.out -XDallowDefaultMethods -XDrawDiagnostics Neg16.java
|
||||
* @compile/fail/ref=Neg16.out -XDrawDiagnostics Neg16.java
|
||||
*/
|
||||
class Neg16 {
|
||||
interface I { default void m() { } }
|
||||
|
|
|
@ -24,14 +24,12 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary basic test for default methods
|
||||
* @ignore awaits lambda support
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowLambda -XDallowPoly -XDallowDefaultMethods Pos01.java
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class Pos01 {
|
||||
public class Pos01 {
|
||||
|
||||
interface Mapper<T> {
|
||||
T map(T in);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary test for explicit resolution of ambiguous default methods
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos02.java
|
||||
* @compile Pos02.java
|
||||
*/
|
||||
|
||||
class Pos02 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary test for overriding with default method
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos04.java
|
||||
* @compile Pos04.java
|
||||
*/
|
||||
|
||||
class Pos04 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that indirectly inherited default methods are discovered during resolution
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos05.java
|
||||
* @compile Pos05.java
|
||||
*/
|
||||
|
||||
class Pos05 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that well-formed MI hierarchies behaves well w.r.t. method resolution (i.e. no ambiguities)
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos06.java
|
||||
* @compile Pos06.java
|
||||
*/
|
||||
|
||||
class Pos06 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that compilation order does not matter
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos07.java
|
||||
* @compile Pos07.java
|
||||
*/
|
||||
|
||||
class Pos07 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that common overrider solves default method conflicts
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos08.java
|
||||
* @compile Pos08.java
|
||||
*/
|
||||
|
||||
class Pos08 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary check that type-variables in generic extension decl can be accessed from default impl
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods Pos10.java
|
||||
* @compile Pos10.java
|
||||
*/
|
||||
|
||||
class Pos10 {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @test
|
||||
* @summary complex test with conflict resolution via overriding
|
||||
* @author Brian Goetz
|
||||
* @compile -XDallowDefaultMethods Pos11.java
|
||||
* @compile Pos11.java
|
||||
*/
|
||||
|
||||
class Pos11 {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary check that 'this' can be used from within an extension method
|
||||
* @compile -XDallowDefaultMethods Pos12.java
|
||||
* @compile Pos12.java
|
||||
*/
|
||||
|
||||
interface Pos12 {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary qualified 'this' inside default method causes StackOverflowException
|
||||
* @compile -XDallowDefaultMethods Pos13.java
|
||||
* @compile Pos13.java
|
||||
*/
|
||||
|
||||
public class Pos13 {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary check that overload resolution selects most specific signature
|
||||
* @compile -XDallowDefaultMethods Pos14.java
|
||||
* @compile Pos14.java
|
||||
*/
|
||||
|
||||
class Pos14 {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary check that overload resolution selects most specific signature
|
||||
* @compile -XDallowDefaultMethods Pos15.java
|
||||
* @compile Pos15.java
|
||||
*/
|
||||
|
||||
class Pos15 {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/*
|
||||
* @test
|
||||
* @summary 'class wins' should not short-circuit overload resolution
|
||||
* @compile -XDallowDefaultMethods Pos16.java
|
||||
* @compile Pos16.java
|
||||
*/
|
||||
|
||||
class Pos16 {
|
||||
|
|
|
@ -23,10 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @ignore awaits for VM support
|
||||
* @summary check that code attributed for default methods is correctly generated
|
||||
* @compile -XDallowDefaultMethods TestDefaultBody.java
|
||||
* @run main TestDefaultBody
|
||||
*/
|
||||
|
||||
import com.sun.tools.classfile.AccessFlags;
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
* @test
|
||||
* @ignore awaits for VM support
|
||||
* @summary check that javac does not generate bridge methods for defaults
|
||||
* @compile -XDallowDefaultMethods TestNoBridgeOnDefaults.java
|
||||
* @run main TestNoBridgeOnDefaults
|
||||
*/
|
||||
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
|
|
|
@ -82,7 +82,7 @@ public class FDTest {
|
|||
|
||||
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
|
||||
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
|
||||
Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source));
|
||||
null, null, Arrays.asList(source));
|
||||
try {
|
||||
ct.analyze();
|
||||
} catch (Throwable ex) {
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
* @test
|
||||
* @summary smoke test for separate compilation of default methods
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile -XDallowDefaultMethods pkg1/A.java
|
||||
* @compile -XDallowDefaultMethods Separate.java
|
||||
* @compile pkg1/A.java
|
||||
* @compile Separate.java
|
||||
*/
|
||||
|
||||
import pkg1.A;
|
||||
|
|
|
@ -323,7 +323,7 @@ public class TestDefaultSuperCall {
|
|||
|
||||
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
|
||||
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
|
||||
Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source));
|
||||
null, null, Arrays.asList(source));
|
||||
try {
|
||||
ct.analyze();
|
||||
} catch (Throwable ex) {
|
||||
|
|
|
@ -54,7 +54,7 @@ public class TestDefaultMethodsSyntax {
|
|||
}
|
||||
|
||||
List<String> getOptions() {
|
||||
return Arrays.asList("-XDallowDefaultMethods", "-source", versionString);
|
||||
return Arrays.asList("-source", versionString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.cant.access.inner.cls.constr
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class CantAccessInnerClsConstructor {
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
// key: compiler.misc.no.conforming.assignment.exists
|
||||
// key: compiler.misc.cant.apply.symbol
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class CantApplySymbolFragment {
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
// key: compiler.misc.inapplicable.method
|
||||
// key: compiler.misc.cant.apply.symbols
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class CantApplySymbolsFragment {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.cant.ref.non.effectively.final.var
|
||||
// key: compiler.misc.inner.cls
|
||||
// key: compiler.misc.lambda
|
||||
// options: -XDallowLambda -XDallowEffectivelyFinalInInnerClasses
|
||||
|
||||
class CantRefNonEffectivelyFinalVar {
|
||||
void test() {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.misc.cant.resolve.location.args
|
||||
// key: compiler.misc.location
|
||||
// key: compiler.err.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class CantResolveLocationArgsFragment {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.misc.cant.resolve.location.args.params
|
||||
// key: compiler.misc.location
|
||||
// key: compiler.err.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class CantResolveLocationArgsParamsFragment {
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.incompatible.ret.type.in.lambda
|
||||
// key: compiler.misc.conditional.target.cant.be.void
|
||||
|
||||
class ConditionalTargetCantBeVoid {
|
||||
|
||||
interface SAM {
|
||||
void m();
|
||||
}
|
||||
|
||||
void test(boolean cond, Object o1, Object o2) {
|
||||
SAM s = ()-> cond ? o1 : o2;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.cant.apply.symbol
|
||||
// key: compiler.misc.cyclic.inference
|
||||
// options: -XDallowLambda -XDallowPoly
|
||||
|
||||
class CyclicInference {
|
||||
interface SAM<X> {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.default.overrides.object.member
|
||||
// options: -XDallowDefaultMethods
|
||||
|
||||
interface DefaultOverridesObjectMember {
|
||||
default String toString() { return ""; }
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.not.a.functional.intf.1
|
||||
// key: compiler.misc.incompatible.abstracts
|
||||
// options: -XDallowLambda
|
||||
|
||||
class IncompatibleAbstracts {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.incompatible.arg.types.in.lambda
|
||||
// options: -XDallowLambda -XDallowPoly
|
||||
|
||||
class IncompatibleArgTypesInLambda {
|
||||
interface SAM {
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
// key: compiler.misc.incompatible.descs.in.functional.intf
|
||||
// key: compiler.misc.descriptor
|
||||
// key: compiler.misc.descriptor.throws
|
||||
// options: -XDallowLambda
|
||||
|
||||
class IncompatibleDescsInFunctionalIntf {
|
||||
interface A {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.inconvertible.types
|
||||
// key: compiler.misc.incompatible.ret.type.in.lambda
|
||||
// options: -XDallowLambda -XDallowPoly
|
||||
|
||||
class IncompatibleRetTypeInLambda {
|
||||
interface SAM {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.inconvertible.types
|
||||
// key: compiler.misc.incompatible.ret.type.in.mref
|
||||
// options: -XDallowMethodReferences -XDallowPoly
|
||||
|
||||
class IncompatibleRetTypeInMref {
|
||||
interface SAM {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.incompatible.thrown.types.in.lambda
|
||||
// options: -XDallowLambda
|
||||
|
||||
class IncompatibleThrownTypesInLambda {
|
||||
interface SAM {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.incompatible.thrown.types.in.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class IncompatibleThrownTypesInMref {
|
||||
interface SAM {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.incompatible.type.in.conditional
|
||||
// key: compiler.misc.inconvertible.types
|
||||
// options: -XDallowPoly
|
||||
|
||||
class IncompatibleTypesInConditional {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.invalid.generic.desc.in.functional.intf
|
||||
// options: -XDallowLambda
|
||||
|
||||
class InvalidGenericDescInFunctionalIntf {
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.local.var.accessed.from.icls.needs.final
|
||||
// options: -Xlint:-options -source 7
|
||||
|
||||
class LocalVarNeedsFinal {
|
||||
Runnable m() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
|
@ -21,7 +21,8 @@
|
|||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.missing.ret.val
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.missing.ret.val
|
||||
|
||||
class MissingReturnValue {
|
||||
int m() {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.incompatible.ret.type.in.lambda
|
||||
// key: compiler.misc.missing.ret.val
|
||||
// options: -XDallowLambda
|
||||
|
||||
class MissingReturnValueFragment {
|
||||
interface SAM {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.not.a.functional.intf.1
|
||||
// key: compiler.misc.no.abstracts
|
||||
// options: -XDallowLambda
|
||||
|
||||
class NoAbstracts {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.no.suitable.functional.intf.inst
|
||||
// options: -XDallowLambda
|
||||
|
||||
class NoSuitableFunctionalIntfInst {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.non-static.cant.be.ref
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class NonStaticCantBeRefFragment {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.not.a.functional.intf
|
||||
// options: -XDallowLambda
|
||||
|
||||
class NotAFunctionalIntf {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.not.def.access.class.intf.cant.access
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class NotDefAccessClassIntfCantAccessFragment {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.illegal.default.super.call
|
||||
// key: compiler.misc.overridden.default
|
||||
// options: -XDallowDefaultMethods
|
||||
|
||||
class OverriddenDefault {
|
||||
interface I { default void m() { } }
|
||||
|
@ -33,4 +32,4 @@ class OverriddenDefault {
|
|||
static class C implements J, K {
|
||||
void foo() { K.super.m(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
|
||||
// key: compiler.note.potential.lambda.found
|
||||
// options: -XDallowLambda -XDidentifyLambdaCandidate=true
|
||||
// options: -XDidentifyLambdaCandidate=true
|
||||
|
||||
class PotentialLambdaFound {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
// key: compiler.err.illegal.default.super.call
|
||||
// key: compiler.misc.redundant.supertype
|
||||
// options: -XDallowDefaultMethods
|
||||
|
||||
class RedundantSupertype {
|
||||
interface I { default void m() { } }
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.ref.ambiguous
|
||||
// key: compiler.misc.invalid.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class RefAmbiguousFragment {
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.types.incompatible.abstract.default
|
||||
// options: -XDallowDefaultMethods
|
||||
|
||||
class TypesIncompatibleAbstractDefault {
|
||||
interface A {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.types.incompatible.unrelated.defaults
|
||||
// options: -XDallowDefaultMethods
|
||||
|
||||
class TypesIncompatibleUnrelatedDefaults {
|
||||
interface A {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.unexpected.lambda
|
||||
// options: -XDallowLambda
|
||||
|
||||
class UnexpectedLambda {
|
||||
{ (()-> { })++; }
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
// key: compiler.err.unexpected.mref
|
||||
// options: -XDallowMethodReferences
|
||||
|
||||
class UnexpectedLambda {
|
||||
{ (Foo::bar)++; }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
|
@ -21,9 +21,10 @@
|
|||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.cant.ret.val.from.meth.decl.void
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.unexpected.ret.val
|
||||
|
||||
class CantReturnValueForVoid {
|
||||
class UnexpectedReturnValue {
|
||||
void m() {
|
||||
return 3;
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
*
|
||||
* @summary Invalid compiler error on covariant overriding methods with the same erasure
|
||||
* @compile -source 7 T7022054pos1.java
|
||||
* @compile/fail -XDstrictMethodClashCheck T7022054pos1.java
|
||||
* @compile/fail/ref=T7022054pos1.out -XDrawDiagnostics T7022054pos1.java
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
T7022054pos1.java:39:25: compiler.err.name.clash.same.erasure.no.override: <X>m(java.lang.String), T7022054pos1.B, m(java.lang.String), T7022054pos1.A, <X>m(java.lang.String), T7022054pos1.B
|
||||
1 error
|
|
@ -27,7 +27,7 @@
|
|||
*
|
||||
* @summary Invalid compiler error on covariant overriding methods with the same erasure
|
||||
* @compile -source 7 T7022054pos2.java
|
||||
* @compile/fail -XDstrictMethodClashCheck T7022054pos2.java
|
||||
* @compile/fail/ref=T7022054pos2.out -XDrawDiagnostics T7022054pos2.java
|
||||
*/
|
||||
|
||||
class T7022054pos2 {
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
T7022054pos2.java:38:32: compiler.err.name.clash.same.erasure.no.hide: <X>m(java.lang.String), T7022054pos2.B, m(java.lang.String), T7022054pos2.A
|
||||
1 error
|
30
langtools/test/tools/javac/lambda/BadAccess.java
Normal file
30
langtools/test/tools/javac/lambda/BadAccess.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that non-static variables are not accessible from static lambdas
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail/ref=BadAccess.out -XDrawDiagnostics BadAccess.java
|
||||
*/
|
||||
|
||||
public class BadAccess {
|
||||
|
||||
int i;
|
||||
static int I;
|
||||
|
||||
interface SAM {
|
||||
int m();
|
||||
}
|
||||
|
||||
static void test1() {
|
||||
int l = 0; //effectively final
|
||||
final int L = 0;
|
||||
SAM s = ()-> i + I + l + L;
|
||||
}
|
||||
|
||||
void test2() {
|
||||
int l = 0; //effectively final
|
||||
final int L = 0;
|
||||
SAM s = ()-> i + I + l + L;
|
||||
}
|
||||
}
|
2
langtools/test/tools/javac/lambda/BadAccess.out
Normal file
2
langtools/test/tools/javac/lambda/BadAccess.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
BadAccess.java:22:22: compiler.err.non-static.cant.be.ref: kindname.variable, i
|
||||
1 error
|
31
langtools/test/tools/javac/lambda/BadAccess02.java
Normal file
31
langtools/test/tools/javac/lambda/BadAccess02.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check lambda can access only effectively-final locals
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail/ref=BadAccess02.out -XDrawDiagnostics BadAccess02.java
|
||||
*/
|
||||
|
||||
public class BadAccess02 {
|
||||
|
||||
interface SAM {
|
||||
int m(int h);
|
||||
}
|
||||
|
||||
static void test1() {
|
||||
int l = 0; //effectively final
|
||||
int j = 0; //non-effectively final
|
||||
j = 2;
|
||||
final int L = 0;
|
||||
SAM s = (int h) -> { int k = 0; return h + j + l + L; };
|
||||
}
|
||||
|
||||
void test2() {
|
||||
int l = 0; //effectively final
|
||||
int j = 0; //non-effectively final
|
||||
j = 2;
|
||||
final int L = 0;
|
||||
SAM s = (int h) -> { int k = 0; return h + k + j + l + L; };
|
||||
}
|
||||
}
|
3
langtools/test/tools/javac/lambda/BadAccess02.out
Normal file
3
langtools/test/tools/javac/lambda/BadAccess02.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
BadAccess02.java:21:52: compiler.err.cant.ref.non.effectively.final.var: j, (compiler.misc.lambda)
|
||||
BadAccess02.java:29:56: compiler.err.cant.ref.non.effectively.final.var: j, (compiler.misc.lambda)
|
||||
2 errors
|
15
langtools/test/tools/javac/lambda/BadAccess03.java
Normal file
15
langtools/test/tools/javac/lambda/BadAccess03.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check lambda cannot assign non-effectively final locals
|
||||
* @compile/fail/ref=BadAccess03.out -XDrawDiagnostics BadAccess03.java
|
||||
*/
|
||||
|
||||
class BadAccess03 {
|
||||
void test() {
|
||||
int k = 0;
|
||||
int n = 2; //effectively final variable
|
||||
Runnable r = ()-> { k = n; }; //error
|
||||
}
|
||||
}
|
2
langtools/test/tools/javac/lambda/BadAccess03.out
Normal file
2
langtools/test/tools/javac/lambda/BadAccess03.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
BadAccess03.java:13:29: compiler.err.cant.ref.non.effectively.final.var: k, (compiler.misc.lambda)
|
||||
1 error
|
44
langtools/test/tools/javac/lambda/BadBreakContinue.java
Normal file
44
langtools/test/tools/javac/lambda/BadBreakContinue.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that break/continue is disallowed in lambda expressions
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail/ref=BadBreakContinue.out -XDrawDiagnostics BadBreakContinue.java
|
||||
*/
|
||||
|
||||
class BadBreakContinue {
|
||||
|
||||
static interface SAM {
|
||||
void m();
|
||||
}
|
||||
|
||||
SAM s1 = ()-> { break; };
|
||||
SAM s2 = ()-> { continue; };
|
||||
SAM s3 = ()-> {
|
||||
SAM s3_1 = ()-> { break; };
|
||||
SAM s3_2 = ()-> { continue; };
|
||||
};
|
||||
|
||||
void testLabelled() {
|
||||
loop: while (true) {
|
||||
SAM s1 = ()-> { break loop; };
|
||||
SAM s2 = ()-> { continue loop; };
|
||||
SAM s3 = ()-> {
|
||||
SAM s3_1 = ()-> { break loop; };
|
||||
SAM s3_2 = ()-> { continue loop; };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void testNonLabelled() {
|
||||
while (true) {
|
||||
SAM s1 = ()-> { break; };
|
||||
SAM s2 = ()-> { continue; };
|
||||
SAM s3 = ()-> {
|
||||
SAM s3_1 = ()-> { break; };
|
||||
SAM s3_2 = ()-> { continue; };
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
13
langtools/test/tools/javac/lambda/BadBreakContinue.out
Normal file
13
langtools/test/tools/javac/lambda/BadBreakContinue.out
Normal file
|
@ -0,0 +1,13 @@
|
|||
BadBreakContinue.java:16:21: compiler.err.break.outside.switch.loop
|
||||
BadBreakContinue.java:17:21: compiler.err.cont.outside.loop
|
||||
BadBreakContinue.java:19:27: compiler.err.break.outside.switch.loop
|
||||
BadBreakContinue.java:20:27: compiler.err.cont.outside.loop
|
||||
BadBreakContinue.java:25:29: compiler.err.undef.label: loop
|
||||
BadBreakContinue.java:26:29: compiler.err.undef.label: loop
|
||||
BadBreakContinue.java:28:35: compiler.err.undef.label: loop
|
||||
BadBreakContinue.java:29:35: compiler.err.undef.label: loop
|
||||
BadBreakContinue.java:36:29: compiler.err.break.outside.switch.loop
|
||||
BadBreakContinue.java:37:29: compiler.err.cont.outside.loop
|
||||
BadBreakContinue.java:39:35: compiler.err.break.outside.switch.loop
|
||||
BadBreakContinue.java:40:35: compiler.err.cont.outside.loop
|
||||
12 errors
|
20
langtools/test/tools/javac/lambda/BadConv03.java
Normal file
20
langtools/test/tools/javac/lambda/BadConv03.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* NPE while checking if subinterface is a SAM type
|
||||
* @compile/fail/ref=BadConv03.out -XDrawDiagnostics BadConv03.java
|
||||
*/
|
||||
|
||||
class BadConv03 {
|
||||
|
||||
interface A {
|
||||
void a();
|
||||
}
|
||||
|
||||
interface B extends A { //not a SAM (2 non-override equivalent abstracts!)
|
||||
void a(int i);
|
||||
}
|
||||
|
||||
B b = ()-> { };
|
||||
}
|
2
langtools/test/tools/javac/lambda/BadConv03.out
Normal file
2
langtools/test/tools/javac/lambda/BadConv03.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
BadConv03.java:19:11: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: (compiler.misc.incompatible.abstracts: kindname.interface, BadConv03.B))
|
||||
1 error
|
22
langtools/test/tools/javac/lambda/BadConv04.java
Normal file
22
langtools/test/tools/javac/lambda/BadConv04.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that ill-formed SAM type generates right diagnostic when SAM converted
|
||||
* @compile/fail/ref=BadConv04.out -XDrawDiagnostics BadConv04.java
|
||||
*/
|
||||
|
||||
class BadConv04 {
|
||||
|
||||
interface I1 {
|
||||
int m();
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
long m();
|
||||
}
|
||||
|
||||
interface SAM extends I1, I2 {}
|
||||
|
||||
SAM s = ()-> { };
|
||||
}
|
3
langtools/test/tools/javac/lambda/BadConv04.out
Normal file
3
langtools/test/tools/javac/lambda/BadConv04.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
BadConv04.java:19:5: compiler.err.types.incompatible.diff.ret: BadConv04.I2, BadConv04.I1, m()
|
||||
BadConv04.java:21:13: compiler.err.prob.found.req: (compiler.misc.incompatible.descs.in.functional.intf: kindname.interface, BadConv04.SAM,{(compiler.misc.descriptor: m, , long, ),(compiler.misc.descriptor: m, , int, )})
|
||||
2 errors
|
21
langtools/test/tools/javac/lambda/BadExpressionLambda.java
Normal file
21
langtools/test/tools/javac/lambda/BadExpressionLambda.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that a conditonal can't be void
|
||||
* @compile/fail/ref=BadExpressionLambda.out -XDrawDiagnostics BadExpressionLambda.java
|
||||
*/
|
||||
|
||||
class BadExpressionLambda {
|
||||
|
||||
interface SAM {
|
||||
void invoke();
|
||||
}
|
||||
|
||||
public static void m() {}
|
||||
|
||||
void test() {
|
||||
SAM sam1 = () -> m(); //ok
|
||||
SAM sam2 = () -> true ? m() : m(); //not ok
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
BadExpressionLambda.java:19:31: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.conditional.target.cant.be.void))
|
||||
1 error
|
191
langtools/test/tools/javac/lambda/BadLambdaExpr.java
Normal file
191
langtools/test/tools/javac/lambda/BadLambdaExpr.java
Normal file
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* 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
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* compile crashes on partial lambda expressions
|
||||
*/
|
||||
|
||||
import com.sun.source.util.JavacTask;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
|
||||
public class BadLambdaExpr {
|
||||
|
||||
static int checkCount = 0;
|
||||
|
||||
enum ParameterListKind {
|
||||
ZERO_ARY("()"),
|
||||
UNARY("(#P)"),
|
||||
TWO_ARY("(#P, #P)"),
|
||||
THREE_ARY("(#P, #P, #P)");
|
||||
|
||||
String parametersTemplateStr;
|
||||
|
||||
ParameterListKind(String parametersTemplateStr) {
|
||||
this.parametersTemplateStr = parametersTemplateStr;
|
||||
}
|
||||
|
||||
String getParameterString(ParameterKind pk) {
|
||||
return parametersTemplateStr.replaceAll("#P", pk.parameterStr);
|
||||
}
|
||||
}
|
||||
|
||||
enum ParameterKind {
|
||||
IMPLICIT("a"),
|
||||
EXPLIICT("A a");
|
||||
|
||||
String parameterStr;
|
||||
|
||||
ParameterKind(String parameterStr) {
|
||||
this.parameterStr = parameterStr;
|
||||
}
|
||||
}
|
||||
|
||||
enum ArrowKind {
|
||||
NONE(""),
|
||||
SEMI("-"),
|
||||
FULL("->");
|
||||
|
||||
String arrowStr;
|
||||
|
||||
ArrowKind(String arrowStr) {
|
||||
this.arrowStr = arrowStr;
|
||||
}
|
||||
}
|
||||
|
||||
enum ExprKind {
|
||||
NONE("#P#A"),
|
||||
METHOD_CALL("m(#P#A)"),
|
||||
CONSTR_CALL("new Foo(#P#A)");
|
||||
|
||||
String expressionTemplate;
|
||||
|
||||
ExprKind(String expressionTemplate) {
|
||||
this.expressionTemplate = expressionTemplate;
|
||||
}
|
||||
|
||||
String expressionString(ParameterListKind plk, ParameterKind pk,
|
||||
ArrowKind ak) {
|
||||
return expressionTemplate.replaceAll("#P", plk.getParameterString(pk))
|
||||
.replaceAll("#A", ak.arrowStr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
|
||||
//create default shared JavaCompiler - reused across multiple compilations
|
||||
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
|
||||
|
||||
for (ParameterListKind plk : ParameterListKind.values()) {
|
||||
for (ParameterKind pk : ParameterKind.values()) {
|
||||
for (ArrowKind ak : ArrowKind.values()) {
|
||||
for (ExprKind ek : ExprKind.values()) {
|
||||
new BadLambdaExpr(plk, pk, ak, ek).run(comp, fm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Total check executed: " + checkCount);
|
||||
}
|
||||
|
||||
ParameterListKind plk;
|
||||
ParameterKind pk;
|
||||
ArrowKind ak;
|
||||
ExprKind ek;
|
||||
JavaSource source;
|
||||
DiagnosticChecker diagChecker;
|
||||
|
||||
BadLambdaExpr(ParameterListKind plk, ParameterKind pk, ArrowKind ak, ExprKind ek) {
|
||||
this.plk = plk;
|
||||
this.pk = pk;
|
||||
this.ak = ak;
|
||||
this.ek = ek;
|
||||
this.source = new JavaSource();
|
||||
this.diagChecker = new DiagnosticChecker();
|
||||
}
|
||||
|
||||
class JavaSource extends SimpleJavaFileObject {
|
||||
|
||||
String template = "class Test {\n" +
|
||||
" SAM s = #E;\n" +
|
||||
"}";
|
||||
|
||||
String source;
|
||||
|
||||
public JavaSource() {
|
||||
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
|
||||
source = template.replaceAll("#E", ek.expressionString(plk, pk, ak));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
|
||||
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
|
||||
null, null, Arrays.asList(source));
|
||||
try {
|
||||
ct.parse();
|
||||
} catch (Throwable ex) {
|
||||
throw new AssertionError("Error thron when parsing the following source:\n" + source.getCharContent(true));
|
||||
}
|
||||
check();
|
||||
}
|
||||
|
||||
void check() {
|
||||
boolean errorExpected =
|
||||
ak != ArrowKind.NONE ||
|
||||
plk != ParameterListKind.UNARY ||
|
||||
pk != ParameterKind.IMPLICIT;
|
||||
if (errorExpected != diagChecker.errorFound) {
|
||||
throw new Error("bad diag for source:\n" +
|
||||
source.getCharContent(true));
|
||||
}
|
||||
checkCount++;
|
||||
}
|
||||
|
||||
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
|
||||
|
||||
boolean errorFound;
|
||||
|
||||
@Override
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
|
||||
errorFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
langtools/test/tools/javac/lambda/BadLambdaPos.java
Normal file
31
langtools/test/tools/javac/lambda/BadLambdaPos.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that lambda is only allowed in argument/cast/assignment context
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail/ref=BadLambdaPos.out -XDrawDiagnostics BadLambdaPos.java
|
||||
*/
|
||||
|
||||
interface SAM {
|
||||
void m(Integer x);
|
||||
}
|
||||
|
||||
class Test {
|
||||
void test(Object x) {}
|
||||
|
||||
void test1() {
|
||||
test((int x)-> { } + (int x)-> { } );
|
||||
test((int x)-> { } instanceof Object );
|
||||
}
|
||||
|
||||
void test2() {
|
||||
int i2 = (int x)-> { } + (int x)-> { };
|
||||
boolean b = (int x)-> { } instanceof Object;
|
||||
}
|
||||
|
||||
void test3() {
|
||||
test((Object)(int x)-> { });
|
||||
Object o = (Object)(int x)-> { };
|
||||
}
|
||||
}
|
9
langtools/test/tools/javac/lambda/BadLambdaPos.out
Normal file
9
langtools/test/tools/javac/lambda/BadLambdaPos.out
Normal file
|
@ -0,0 +1,9 @@
|
|||
BadLambdaPos.java:18:14: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:18:30: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:19:14: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:23:18: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:23:34: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:24:21: compiler.err.unexpected.lambda
|
||||
BadLambdaPos.java:28:22: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf)
|
||||
BadLambdaPos.java:29:28: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf)
|
||||
8 errors
|
16
langtools/test/tools/javac/lambda/BadMethodCall.java
Normal file
16
langtools/test/tools/javac/lambda/BadMethodCall.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that diagnostics on nested erroneous deferred types are flushed
|
||||
* @compile/fail/ref=BadMethodCall.out -XDrawDiagnostics BadMethodCall.java
|
||||
*/
|
||||
import java.util.*;
|
||||
|
||||
class BadMethodCall {
|
||||
<I> List<I> id(List<I> z) { return null; };
|
||||
|
||||
List<String> cons(String s, List<String> ls) { return null; }
|
||||
|
||||
void test(List<Object> lo) { Object t = cons(id(""),lo); }
|
||||
}
|
2
langtools/test/tools/javac/lambda/BadMethodCall.out
Normal file
2
langtools/test/tools/javac/lambda/BadMethodCall.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
BadMethodCall.java:15:50: compiler.err.cant.apply.symbol: kindname.method, id, java.util.List<I>, java.lang.String, kindname.class, BadMethodCall, (compiler.misc.infer.no.conforming.assignment.exists: I, (compiler.misc.inconvertible.types: java.lang.String, java.util.List<I>))
|
||||
1 error
|
19
langtools/test/tools/javac/lambda/BadRecovery.java
Normal file
19
langtools/test/tools/javac/lambda/BadRecovery.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* 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; }); });
|
||||
}
|
||||
}
|
3
langtools/test/tools/javac/lambda/BadRecovery.out
Normal file
3
langtools/test/tools/javac/lambda/BadRecovery.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
BadRecovery.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, BadRecovery.SAM1, @369, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda))
|
||||
BadRecovery.java:17:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null)
|
||||
2 errors
|
38
langtools/test/tools/javac/lambda/BadReturn.java
Normal file
38
langtools/test/tools/javac/lambda/BadReturn.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that incompatible return types in lambdas are flagged with error
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail/ref=BadReturn.out -XDrawDiagnostics BadReturn.java
|
||||
*/
|
||||
|
||||
class BadReturn {
|
||||
|
||||
interface SAM {
|
||||
Comparable<?> m();
|
||||
}
|
||||
|
||||
static void testNeg1() {
|
||||
SAM s = ()-> {
|
||||
if (true) {
|
||||
return "";
|
||||
} else {
|
||||
return System.out.println("");
|
||||
}};
|
||||
}
|
||||
|
||||
static void testNeg2() {
|
||||
SAM s = ()-> { return System.out.println(""); };
|
||||
}
|
||||
|
||||
static void testPos() {
|
||||
SAM s = ()-> {
|
||||
if (false) {
|
||||
return 10;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}};
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue