mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
new inference: do not accept varargs when array is passed there
This commit is contained in:
@@ -173,9 +173,25 @@ public class InferenceSession {
|
||||
private static PsiType getParameterType(PsiParameter[] parameters, PsiExpression[] args, int i, PsiSubstitutor substitutor) {
|
||||
PsiType parameterType = substitutor.substitute(parameters[i < parameters.length ? i : parameters.length - 1].getType());
|
||||
if (parameterType instanceof PsiEllipsisType) {
|
||||
if (args.length != parameters.length ||
|
||||
PsiPolyExpressionUtil.isPolyExpression(args[i]) ||
|
||||
args[i] != null && !(args[i].getType() instanceof PsiArrayType)) {
|
||||
final PsiExpression arg = args[i];
|
||||
if (arg instanceof PsiNewExpression) {
|
||||
if (((PsiNewExpression)arg).getArrayDimensions().length == parameterType.getArrayDimensions() || ((PsiNewExpression)arg).getArrayInitializer() != null) {
|
||||
return parameterType;
|
||||
}
|
||||
}
|
||||
if (arg instanceof PsiMethodCallExpression) {
|
||||
final PsiMethod method = ((PsiMethodCallExpression)arg).resolveMethod();
|
||||
if (method != null) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (returnType != null && returnType.getArrayDimensions() == parameterType.getArrayDimensions()) {
|
||||
return parameterType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != parameters.length ||
|
||||
PsiPolyExpressionUtil.isPolyExpression(arg) ||
|
||||
arg != null && !(arg.getType() instanceof PsiArrayType)) {
|
||||
parameterType = ((PsiEllipsisType)parameterType).getComponentType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.util.Set;
|
||||
|
||||
class FooBar {
|
||||
Set<String> strings = null;
|
||||
{
|
||||
bar(strings.toArray(new String[strings.size()]));
|
||||
}
|
||||
|
||||
void bar(String... a){}
|
||||
}
|
||||
@@ -136,6 +136,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testArrayPassedToVarargsMethod() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user