mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-03 15:50:52 +07:00
lambda: tests
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
interface I1 {
|
||||
void m();
|
||||
}
|
||||
|
||||
interface I2<X> {
|
||||
X m();
|
||||
}
|
||||
|
||||
class Ambiguity1 {
|
||||
|
||||
static void m(I1 i1) {}
|
||||
static <T> void m(I2<T> i2) {}
|
||||
|
||||
{
|
||||
m<error descr="Ambiguous method call: both 'Ambiguity1.m(I1)' and 'Ambiguity1.m(I2<Object>)' match">(()->{throw new AssertionError();})</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface I {
|
||||
void m();
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
int m();
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
String m();
|
||||
}
|
||||
|
||||
interface I3<A> {
|
||||
A m();
|
||||
}
|
||||
|
||||
class AmbiguityRawGenerics {
|
||||
|
||||
void foo(I s) { }
|
||||
void foo(I1 s) { }
|
||||
void foo(I2 s) { }
|
||||
<Z> void foo(I3<Z> s) { }
|
||||
|
||||
void bar() {
|
||||
foo<error descr="Ambiguous method call: both 'AmbiguityRawGenerics.foo(I)' and 'AmbiguityRawGenerics.foo(I1)' match">(()-> { throw new RuntimeException(); })</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
interface I {
|
||||
void m();
|
||||
}
|
||||
|
||||
interface I1<A> {
|
||||
void m(A a);
|
||||
}
|
||||
|
||||
interface I2<A> {
|
||||
void m(A a1, A a2);
|
||||
}
|
||||
|
||||
interface IV<A> {
|
||||
void m(A... as);
|
||||
}
|
||||
|
||||
class AmbiguityVarargs {
|
||||
void foo(I s) { }
|
||||
void foo(I1<String> s) { }
|
||||
void foo(I2<String> s) { }
|
||||
void foo(IV<String> s) { }
|
||||
|
||||
void test() {
|
||||
foo(()->{});
|
||||
foo<error descr="Ambiguous method call: both 'AmbiguityVarargs.foo(I1<String>)' and 'AmbiguityVarargs.foo(IV<String>)' match">((a1) -> {})</error>;
|
||||
foo((a1, a2)->{});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface I {
|
||||
void m(int x);
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
int m();
|
||||
}
|
||||
class CastInContexts {
|
||||
void m(I s) { }
|
||||
|
||||
void assignment() {
|
||||
I i1 = (I)(x-> { System.out.println(); });
|
||||
I i2 = (I)((x-> { System.out.println(); }));
|
||||
}
|
||||
|
||||
void method() {
|
||||
m((I)(x-> { System.out.println(); }));
|
||||
}
|
||||
|
||||
I returnContext() {
|
||||
return (I)(x -> { System.out.println(); });
|
||||
}
|
||||
|
||||
{
|
||||
int i = <error descr="Inconvertible types; cannot cast '<lambda expression>' to 'int'">(int) ()-> 1</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
interface I {
|
||||
void m(int x);
|
||||
}
|
||||
class InContexts {
|
||||
void m(I s) { }
|
||||
|
||||
void assignment() {
|
||||
I s1 = (x-> { System.out.println(); });
|
||||
I s2 = ((x-> { System.out.println(); }));
|
||||
}
|
||||
|
||||
void method() {
|
||||
m((x-> { System.out.println(); }));
|
||||
m(((x-> { System.out.println(); })));
|
||||
}
|
||||
|
||||
I returnContext() {
|
||||
return (x -> {System.out.println();});
|
||||
}
|
||||
}
|
||||
|
||||
interface I1<A, B> {
|
||||
B foo(A a);
|
||||
}
|
||||
class ValueLambdaInContext {
|
||||
|
||||
<Z> void m1(I1<String, Z> i) { }
|
||||
<Z> void m2(I1<String, I1<String, Z>> i) { }
|
||||
|
||||
void exprMethod() {
|
||||
m1(s1 -> 1);
|
||||
m2(s1 -> s2 -> 1);
|
||||
}
|
||||
|
||||
void exprAssignment() {
|
||||
I1<String, Integer> in1 = s1 -> 1;
|
||||
I1<String, I1<String, Integer>> in2 = s1 -> s2 -> 1;
|
||||
}
|
||||
|
||||
void statementMethod() {
|
||||
m1(s1 -> { return 1; });
|
||||
m2(s1 -> { return s2 -> { return 1; }; });
|
||||
}
|
||||
|
||||
void statementAssignment() {
|
||||
I1<String, Integer> in1 = s1 -> { return 1; };
|
||||
I1<String, I1<String, Integer>> in2 = s1 -> { return s2 -> { return 1; }; };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
interface I<K, V> {
|
||||
public V put(K k, V v);
|
||||
}
|
||||
|
||||
interface A<T>{}
|
||||
interface B<L> extends A<L>{}
|
||||
|
||||
interface SameArgsI<T> {
|
||||
T same(T a, T b);
|
||||
}
|
||||
|
||||
class InferenceFromArgs {
|
||||
|
||||
private static <E> void bar(A<? extends E> a, I<? super E, Integer> i) { }
|
||||
|
||||
void foo(B<Integer> b) {
|
||||
bar(b, (k, v) -> {int i = k; int j = v; return Math.max(i, j);});
|
||||
}
|
||||
|
||||
public static <T> SameArgsI<T> max() {
|
||||
return (a, b) -> b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
interface I<A, B> {
|
||||
B foo(A a);
|
||||
}
|
||||
class NoInferenceResult {
|
||||
|
||||
<A, B> I<A, B> m(I<A, B> f) { return null; }
|
||||
<T> void m1(T t) { }
|
||||
|
||||
void test() {
|
||||
m<error descr="'m(I<java.lang.Object,java.lang.Object>)' in 'NoInferenceResult' cannot be applied to '(<lambda expression>)'">((String s1) -> (String s2) -> s1 + s2)</error>;
|
||||
|
||||
m((String s1) -> s1.length());
|
||||
m((String s1) -> s1);
|
||||
|
||||
m1<error descr="'m1(java.lang.Object)' in 'NoInferenceResult' cannot be applied to '(<lambda expression>)'">(() -> { })</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class TypeArgsConsistency {
|
||||
|
||||
interface I<T> {
|
||||
T m(int i, int j);
|
||||
}
|
||||
|
||||
static void foo(I<Integer> s) { }
|
||||
|
||||
static <X> I<X> bar(I<X> s) { return null; }
|
||||
|
||||
{
|
||||
I<Integer> i1 = (i, j) -> i + j;
|
||||
foo((i, j) -> i + j);
|
||||
I<Integer> i2 = bar((i, j) -> i + j);
|
||||
I<Integer> i3 = bar<error descr="'bar(TypeArgsConsistency.I<java.lang.Integer>)' in 'TypeArgsConsistency' cannot be applied to '(<lambda expression>)'">((i, j) -> "" + i + j)</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class WildcardBounds {
|
||||
|
||||
interface I<T> {
|
||||
T foo(T a, T b);
|
||||
}
|
||||
|
||||
void m1(I<? extends String> f1) {}
|
||||
void m2(I<? super String> f2) {}
|
||||
void m3(I<?> f3) {}
|
||||
|
||||
I<? extends String> f1 = (a, b) -> a;
|
||||
I<? super String> f2 = (a, b) -> a;
|
||||
I<?> f3 = (a, b) -> a;
|
||||
|
||||
{
|
||||
m1((a, b) -> a);
|
||||
m2((a, b) -> a);
|
||||
m3((a, b) -> a);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user