lambda: check formal types for equality

This commit is contained in:
Anna Kozlova
2012-08-20 21:35:13 +04:00
parent e8fff2c2b4
commit d2b956c808
3 changed files with 14 additions and 3 deletions

View File

@@ -141,12 +141,12 @@ public class LambdaUtil {
final PsiType lambdaFormalType = typeElement.getType();
final PsiType methodParameterType = parameterTypes[lambdaParamIdx];
if (lambdaFormalType instanceof PsiPrimitiveType) {
if (methodParameterType instanceof PsiPrimitiveType) return methodParameterType.isAssignableFrom(lambdaFormalType);
if (methodParameterType instanceof PsiPrimitiveType) return methodParameterType.equals(lambdaFormalType);
return false;
}
if (!resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodParameterType))
.isAssignableFrom(lambdaFormalType)) {
if (!lambdaFormalType
.equals(resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodParameterType)))) {
return false;
}
}

View File

@@ -0,0 +1,7 @@
class Test {
{
<error descr="Incompatible types. Found: '<lambda expression>', required: 'java.lang.Comparable'">Comparable c = (String o)->{
return 0;
};</error>
}
}

View File

@@ -37,6 +37,10 @@ public class LambdaParamsTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testRaw() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}