diff --git a/java/java-psi-api/src/com/intellij/psi/impl/source/resolve/graphInference/PsiPolyExpressionUtil.java b/java/java-psi-api/src/com/intellij/psi/impl/source/resolve/graphInference/PsiPolyExpressionUtil.java index aa24967d32b6..319021f1e0c3 100644 --- a/java/java-psi-api/src/com/intellij/psi/impl/source/resolve/graphInference/PsiPolyExpressionUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/impl/source/resolve/graphInference/PsiPolyExpressionUtil.java @@ -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; } diff --git a/java/java-tests/testData/psi/resolve/method/SwitchExpressionType.java b/java/java-tests/testData/psi/resolve/method/SwitchExpressionType.java new file mode 100644 index 000000000000..8ac49ce50d89 --- /dev/null +++ b/java/java-tests/testData/psi/resolve/method/SwitchExpressionType.java @@ -0,0 +1,8 @@ +class SwitchExpressionType { + public static void main(String[] args) { + System.out.print(switch (args.length) { + case 1 -> 1; + default -> 2; + }); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/psi/resolve/ResolveMethodTest.java b/java/java-tests/testSrc/com/intellij/java/psi/resolve/ResolveMethodTest.java index ee840cb216b0..55937b2ca128 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/resolve/ResolveMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/resolve/ResolveMethodTest.java @@ -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));