mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
lambda: return type void-compatibility checks extracted
This commit is contained in:
+1
-1
@@ -12,6 +12,6 @@ class Ambiguity1 {
|
||||
static <T> void m(I2<T> i2) {}
|
||||
|
||||
{
|
||||
m<error descr="Ambiguous method call: both 'Ambiguity1.m(I1)' and 'Ambiguity1.m(I2<T>)' match">(()->{throw new AssertionError();})</error>;
|
||||
m<error descr="Ambiguous method call: both 'Ambiguity1.m(I1)' and 'Ambiguity1.m(I2<Object>)' match">(()->{throw new AssertionError();})</error>;
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
class Test1 {
|
||||
|
||||
interface VoidReturnType {
|
||||
void foo();
|
||||
}
|
||||
{
|
||||
VoidReturnType aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
VoidReturnType aI1 = () -> {System.out.println();};
|
||||
VoidReturnType aI2 = <error descr="Cannot return a value from method whose result type is void">() -> {return 1;}</error>;
|
||||
VoidReturnType aI3 = <error descr="Incompatible return type int in lambda expression">() -> 1</error>;
|
||||
VoidReturnType aI4 = () -> {return;};
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
interface IntReturnType {
|
||||
int foo();
|
||||
}
|
||||
{
|
||||
IntReturnType aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
IntReturnType aI1 = <error descr="Incompatible return type void in lambda expression">() -> {System.out.println();}</error>;
|
||||
IntReturnType aI2 = () -> {return 1;};
|
||||
IntReturnType aI3 = () -> 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Test3 {
|
||||
|
||||
interface XReturnType<X> {
|
||||
X foo();
|
||||
}
|
||||
{
|
||||
XReturnType<Object> aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
XReturnType<Object> aI1 = <error descr="Incompatible return type void in lambda expression">() -> {System.out.println();}</error>;
|
||||
XReturnType<Object> aI2 = () -> {return 1;};
|
||||
XReturnType<Object> aI3 = () -> 1;
|
||||
XReturnType<Object> aI4 = <error descr="Incompatible return type void in lambda expression">() -> {}</error>;
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
class Y<T>{}
|
||||
|
||||
interface YXReturnType<X> {
|
||||
Y<X> foo();
|
||||
}
|
||||
|
||||
{
|
||||
YXReturnType<Object> aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
YXReturnType<Object> aI1 = <error descr="Incompatible return type void in lambda expression">() -> {System.out.println();}</error>;
|
||||
YXReturnType<Object> aI2 = <error descr="Incompatible return type int in lambda expression">() -> {return 1;}</error>;
|
||||
YXReturnType<Object> aI3 = <error descr="Incompatible return type int in lambda expression">() -> 1</error>;
|
||||
YXReturnType<Object> aI4 = () -> new Y<Object>(){};
|
||||
YXReturnType<Object> aIDiamond = () -> new Y<>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,5 +68,5 @@ class ReturnTypeChecks1 {
|
||||
}
|
||||
|
||||
I<Integer, Integer> accepted = i -> { return i; };
|
||||
<error descr="Incompatible types. Found: '<lambda expression>', required: 'ReturnTypeChecks1.I<java.lang.Double,java.lang.Integer>'">I<Double, Integer> rejected = i -> { return i; };</error>
|
||||
I<Double, Integer> rejected = <error descr="Incompatible return type Double in lambda expression">i -> { return i; }</error>;
|
||||
}
|
||||
|
||||
+4
-4
@@ -32,7 +32,7 @@ class Test1 {
|
||||
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>
|
||||
I<String> lS = <error descr="Incompatible return type List<String> in lambda expression">x->x</error>;
|
||||
bar2("", lS);
|
||||
|
||||
bar2("", x -> x);
|
||||
@@ -66,9 +66,9 @@ class Test2 {
|
||||
{
|
||||
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>;
|
||||
bar2(1, <error descr="Incompatible return type List<Integer> in lambda expression">x -> x</error>);
|
||||
bar2("", <error descr="Incompatible return type List<String> in lambda expression">x -> x</error>);
|
||||
bar3(<error descr="Incompatible return type List<String> in lambda expression">x -> x</error>, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ class Test5 {
|
||||
static <T> void bar(I<T> i){}
|
||||
|
||||
{
|
||||
bar<error descr="'bar(Test5.I<T>)' in 'Test5' cannot be applied to '(<lambda expression>)'">(() -> null)</error>;
|
||||
bar(<error descr="Incompatible return type <null> in lambda expression">() -> null</error>);
|
||||
}
|
||||
}
|
||||
class Test6 {
|
||||
@@ -30,7 +30,7 @@ class Test6 {
|
||||
static <T> void bar(I<T> i){}
|
||||
|
||||
{
|
||||
bar<error descr="'bar(Test6.I<java.lang.Object>)' in 'Test6' cannot be applied to '(<lambda expression>)'">(() -> null)</error>;
|
||||
bar(<error descr="Incompatible return type <null> in lambda expression">() -> null</error>);
|
||||
bar(() -> {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user