mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
lambda: do not distinguish between ellipsis and arrays for formal lambda params checks (IDEA-117124)
(cherry picked from commit 03b253b084ddb93ce485b1997d47a4b00284eb74)
This commit is contained in:
@@ -314,7 +314,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult);
|
||||
if (expression.hasFormalParameterTypes()) {
|
||||
for (int i = 0; i < lambdaParameters.length; i++) {
|
||||
if (!Comparing.equal(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType()))) {
|
||||
if (!PsiTypesUtil.compareTypes(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType()), true)) {
|
||||
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.range(lambdaParameters[i])
|
||||
.descriptionAndTooltip(incompatibleTypesMessage)
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -215,4 +216,16 @@ public class PsiTypesUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean compareTypes(PsiType leftType, PsiType rightType, boolean ignoreEllipsis) {
|
||||
if (ignoreEllipsis) {
|
||||
if (leftType instanceof PsiEllipsisType) {
|
||||
leftType = ((PsiEllipsisType)leftType).toArrayType();
|
||||
}
|
||||
if (rightType instanceof PsiEllipsisType) {
|
||||
rightType = ((PsiEllipsisType)rightType).toArrayType();
|
||||
}
|
||||
}
|
||||
return Comparing.equal(leftType, rightType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
interface Var {
|
||||
void var(int... ps);
|
||||
}
|
||||
|
||||
class Abc {
|
||||
void foo() {
|
||||
Var var = (int[] ps) -> {};
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEllipsis() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user