mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 13:39:36 +07:00
lambda: missed return statement error; do not use containing method return type for lambda inference
This commit is contained in:
@@ -25,7 +25,7 @@ class Test {
|
||||
{
|
||||
boolean flag = true;
|
||||
I i = flag ? (() -> 123) : (() -> 222);
|
||||
I i1 = flag ? (<error descr="Missing return value">() -> {}</error>) : (() -> 222);
|
||||
I i1 = flag ? (() -> {<error descr="Missing return statement">}</error>) : (() -> 222);
|
||||
Object i2 = flag ? (<error descr="Target type of a lambda conversion must be an interface">() -> 42</error>) : (<error descr="Target type of a lambda conversion must be an interface">() -> 222</error>);
|
||||
I i3 = flag ? (<error descr="Incompatible parameter types in lambda expression">(x) -> 42</error>) : (() -> 222);
|
||||
I i4 = flag ? (() -> 42) : new I() {
|
||||
|
||||
@@ -18,7 +18,7 @@ class Test2 {
|
||||
}
|
||||
{
|
||||
IntReturnType aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
IntReturnType aI1 = <error descr="Missing return value">() -> {System.out.println();}</error>;
|
||||
IntReturnType aI1 = () -> {System.out.println();<error descr="Missing return statement">}</error>;
|
||||
IntReturnType aI2 = () -> {return 1;};
|
||||
IntReturnType aI3 = () -> 1;
|
||||
}
|
||||
@@ -32,10 +32,10 @@ class Test3 {
|
||||
}
|
||||
{
|
||||
XReturnType<Object> aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
XReturnType<Object> aI1 = <error descr="Missing return value">() -> {System.out.println();}</error>;
|
||||
XReturnType<Object> aI1 = () -> {System.out.println();<error descr="Missing return statement">}</error>;
|
||||
XReturnType<Object> aI2 = () -> {return 1;};
|
||||
XReturnType<Object> aI3 = () -> 1;
|
||||
XReturnType<Object> aI4 = <error descr="Missing return value">() -> {}</error>;
|
||||
XReturnType<Object> aI4 = () -> {<error descr="Missing return statement">}</error>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Test4 {
|
||||
|
||||
{
|
||||
YXReturnType<Object> aI = <error descr="Incompatible return type void in lambda expression">() -> System.out.println()</error>;
|
||||
YXReturnType<Object> aI1 = <error descr="Missing return value">() -> {System.out.println();}</error>;
|
||||
YXReturnType<Object> aI1 = () -> {System.out.println();<error descr="Missing return statement">}</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>(){};
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
class Test1 {
|
||||
interface Extractor<T, W> {
|
||||
Option<W> unapply(T t);
|
||||
}
|
||||
|
||||
public static abstract class Option<T> {
|
||||
private static class None<T> extends Option<T> {}
|
||||
|
||||
private static final Option NONE = new None();
|
||||
|
||||
public static <T> Option<T> none() {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static <T> Option<T> option(T value) {
|
||||
if (value == null) {
|
||||
return NONE;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Extractor<String, Integer> e = s -> {
|
||||
if (s.equals("1")) {
|
||||
return Option.option(1);
|
||||
} else {
|
||||
return Option.none();
|
||||
}
|
||||
};
|
||||
|
||||
Extractor<String, Integer> e1 = <error descr="Incompatible return type Option<String> in lambda expression">s -> {
|
||||
if (s.equals("1")) {
|
||||
return Option.option(1);
|
||||
} else {
|
||||
return Option.option("2");
|
||||
}
|
||||
}</error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test1 {
|
||||
{
|
||||
Comparable<String> c = o -> {
|
||||
if (o == null) return 1;
|
||||
return -1;
|
||||
<error descr="Unreachable statement">System.out.println("Hello");</error>
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user