mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java: fix type inference for switch expressions (IDEA-311533)
(cherry picked from commit 153bc92d71655760c10d5b7e42d3600310845f42) IJ-CR-169493 GitOrigin-RevId: abb04fd700cb2bbf746bbd644117854929ef36b8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fcc5e59573
commit
39ae7a117c
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.impl.source.resolve.graphInference;
|
||||
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
@@ -210,6 +210,7 @@ public final class PsiPolyExpressionUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return switchKind;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class SwitchExpressionType {
|
||||
public static void main(String[] args) {
|
||||
System.out.<caret>print(switch (args.length) {
|
||||
case 1 -> 1;
|
||||
default -> 2;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.psi.resolve;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.LightResolveTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -259,6 +261,13 @@ public class ResolveMethodTest extends LightResolveTestCase {
|
||||
assertEquals("PublicCloneable", method.getContainingClass().getName());
|
||||
}
|
||||
|
||||
public void testSwitchExpressionType() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_8, () -> {
|
||||
PsiMethod target = (PsiMethod)resolve();
|
||||
assertEquals(PsiTypes.intType(), target.getParameterList().getParameters()[0].getType());
|
||||
});
|
||||
}
|
||||
|
||||
public void testMultipleJavadocReference() {
|
||||
PsiJavaReference ref = (PsiJavaReference)findReferenceAtCaret("method/" + getTestName(false) + ".java");
|
||||
assertSize(3, ref.multiResolve(false));
|
||||
|
||||
Reference in New Issue
Block a user