mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
lambda (IDEA-90043)
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ class InferenceFromArgs {
|
||||
bar(b, (k, v) -> {Integer i = k; return v;});
|
||||
|
||||
bazz(<error descr="Cyclic inference">(k, v) -> v</error>);
|
||||
bazz((k, v) -> {<error descr="Incompatible types. Found: 'E', required: 'int'">int i = k;</error> return v;});
|
||||
bazz((k, v) -> {<error descr="Incompatible types. Found: '<lambda parameter>', required: 'int'">int i = k;</error> return v;});
|
||||
}
|
||||
|
||||
public static <T> SameArgsI<T> max() {
|
||||
|
||||
+60
@@ -15,3 +15,63 @@ class TypeArgsConsistency {
|
||||
<error descr="Incompatible types. Found: 'TypeArgsConsistency.I<java.lang.String>', required: 'TypeArgsConsistency.I<java.lang.Integer>'">I<Integer> i3 = bar((i, j) -> "" + i + j);</error>
|
||||
}
|
||||
}
|
||||
|
||||
class TypeArgsConsistency1 {
|
||||
|
||||
interface I<T> {
|
||||
int m(int i, T 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(<error descr="Cyclic inference">(i, j) -> i</error>) ;
|
||||
I<Integer> i3 = bar(<error descr="Cyclic inference">(i, j) -> "" + i + j</error>);
|
||||
}
|
||||
}
|
||||
|
||||
class TypeArgsConsistency2 {
|
||||
static <T> I<T> bar(I<T> i) {return null;}
|
||||
static <T> I1<T> bar1(I1<T> i) {return null;}
|
||||
static <T> I2<T> bar2(I2<T> i) {return i;}
|
||||
|
||||
public static void main(String[] args) {
|
||||
I<Integer> i1 = bar(<error descr="Cyclic inference">x -> x</error>);
|
||||
I1<Integer> i2 = bar1(<error descr="Cyclic inference">x -> 1</error>);
|
||||
I2<String> aI2 = bar2(x -> "");
|
||||
<error descr="Incompatible types. Found: 'TypeArgsConsistency2.I2<java.lang.String>', required: 'TypeArgsConsistency2.I2<java.lang.Integer>'">I2<Integer> aI28 = bar2( x-> "");</error>
|
||||
I2<Integer> i3 = bar2(x -> x);
|
||||
I2<Integer> i4 = bar2(x -> foooI());
|
||||
System.out.println(i4.foo(2));
|
||||
}
|
||||
|
||||
static <K> K fooo(){return null;}
|
||||
static int foooI(){return 0;}
|
||||
|
||||
interface I<X> {
|
||||
X foo(X x);
|
||||
}
|
||||
interface I1<X> {
|
||||
|
||||
int foo(X x);
|
||||
}
|
||||
|
||||
interface I2<X> {
|
||||
X foo(int x);
|
||||
}
|
||||
}
|
||||
|
||||
class TypeArgsConsistency3 {
|
||||
public static void main(String[] args) {
|
||||
doIt1(1, x -> doIt1(x, y -> x * y));
|
||||
doIt1(1, x -> x);
|
||||
doIt1(1, x -> x * x);
|
||||
}
|
||||
interface F1<ResultType, P1> { ResultType _(P1 p); }
|
||||
static <T> T doIt1(T i, F1<T,T> f) { return f._(i);}
|
||||
}
|
||||
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import java.util.List;
|
||||
class Test1 {
|
||||
|
||||
interface I<X> {
|
||||
X foo(List<String> list);
|
||||
}
|
||||
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
static <T> void bar1(I<T> i){}
|
||||
static <T> void bar2(T t, I<T> i){}
|
||||
static <T> void bar3(I<T> i, T t){}
|
||||
|
||||
{
|
||||
bar(x -> x);
|
||||
bar1(x -> x);
|
||||
|
||||
I<Object> lO = x->x;
|
||||
bar2("", lO);
|
||||
|
||||
<error descr="Incompatible types. Found: '<lambda expression>', required: 'Test1.I<java.lang.String>'">I<String> lS = x->x;</error>
|
||||
bar2("", lS);
|
||||
|
||||
bar2("", x -> x);
|
||||
|
||||
bar3(x -> x, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Test2 {
|
||||
|
||||
interface I<X> {
|
||||
X foo(List<X> list);
|
||||
}
|
||||
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
static <T> void bar1(I<T> i){}
|
||||
static <T> void bar2(T t, I<T> i){}
|
||||
static <T> void bar3(I<T> i, T t){}
|
||||
|
||||
{
|
||||
bar(<error descr="Cyclic inference">x -> x</error>);
|
||||
bar1(<error descr="Cyclic inference">x -> x</error>);
|
||||
bar2<error descr="'bar2(java.lang.Integer, Test2.I<java.lang.Integer>)' in 'Test2' cannot be applied to '(int, <lambda expression>)'">(1, x -> x)</error>;
|
||||
bar2<error descr="'bar2(java.lang.String, Test2.I<java.lang.String>)' in 'Test2' cannot be applied to '(java.lang.String, <lambda expression>)'">("", x -> x)</error>;
|
||||
bar3<error descr="'bar3(Test2.I<java.lang.String>, java.lang.String)' in 'Test2' cannot be applied to '(<lambda expression>, java.lang.String)'">(x -> x, "")</error>;
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
|
||||
interface I<X> {
|
||||
List<X> foo(List<X> list);
|
||||
}
|
||||
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
static <T> void bar1(I<T> i){}
|
||||
static <T> void bar2(T t, I<T> i){}
|
||||
static <T> void bar3(I<T> i, T t){}
|
||||
|
||||
{
|
||||
bar(<error descr="Cyclic inference">x -> x</error>);
|
||||
bar1(<error descr="Cyclic inference">x -> x</error>);
|
||||
bar2(1, x -> x);
|
||||
bar2("", x -> x);
|
||||
|
||||
bar3(x -> x, "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user