mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
lambda: return type compatibility test
This commit is contained in:
@@ -306,7 +306,14 @@ public class LambdaUtil {
|
||||
@Nullable
|
||||
private static PsiType getReturnType(PsiClass psiClass, MethodSignature methodSignature) {
|
||||
final PsiMethod method = getMethod(psiClass, methodSignature);
|
||||
return method != null ? method.getReturnType() : null;
|
||||
if (method != null) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) return null;
|
||||
return TypeConversionUtil.getSuperClassSubstitutor(containingClass, psiClass, PsiSubstitutor.EMPTY).substitute(method.getReturnType());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
class Test {
|
||||
|
||||
interface I<A, B> {
|
||||
B f(A a);
|
||||
}
|
||||
|
||||
interface II<A, B> extends I<A,B> { }
|
||||
|
||||
static class Foo<A> {
|
||||
boolean forAll(final I<A, Boolean> f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String forAll(final II<A, String> f) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String forAll2(final II<A, String> f) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void foo(Foo<String> as, final Foo<Character> ac) {
|
||||
boolean b1 = as.forAll(s -> ac.forAll(c -> false));
|
||||
String s1 = as.forAll(s -> ac.forAll(c -> ""));
|
||||
<error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">boolean b2 = as.forAll(s -> ac.forAll(c -> ""));</error>
|
||||
String s2 = as.forAll2(s -> ac.forAll2(<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
|
||||
boolean b3 = as.forAll((I<String, Boolean>)s -> ac.forAll((I<Character, Boolean>)<error descr="Incompatible return type String in lambda expression">c -> ""</error>));
|
||||
String s3 = as.forAll((II<String, String>)s -> ac.forAll((II<Character, String>)<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testLambdaRawOrNot() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReturnTypeCompatibility1() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoInferenceResult() throws Exception {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user