[java-highlighting] GenericsUtil.getLeastUpperBound: support PsiDisjunctionType

Fixes IDEA-320698 False positive error highlighting of an expression with an union type in a throw statement

GitOrigin-RevId: 7120053a75edbcb8717657b9791d1a310a581c32
This commit is contained in:
Tagir Valeev
2023-06-06 16:56:20 +02:00
committed by intellij-monorepo-bot
parent b47e2068ba
commit 379a59d56b
3 changed files with 24 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi;
import com.intellij.openapi.diagnostic.Logger;
@@ -46,6 +46,13 @@ public final class GenericsUtil {
return getLeastUpperBound(type1, ((PsiCapturedWildcardType)type2).getUpperBound(), compared, manager);
}
if (type1 instanceof PsiDisjunctionType) {
return getLeastUpperBound(((PsiDisjunctionType)type1).getLeastUpperBound(), type2, compared, manager);
}
if (type2 instanceof PsiDisjunctionType) {
return getLeastUpperBound(type1, ((PsiDisjunctionType)type2).getLeastUpperBound(), compared, manager);
}
if (type1 instanceof PsiWildcardType) {
return getLeastUpperBound(((PsiWildcardType)type1).getExtendsBound(), type2, compared, manager);
}

View File

@@ -0,0 +1,14 @@
class SomeClass {
static class Ex1 extends Exception {}
static class Ex2 extends Exception {}
native void run() throws Ex1, Ex2;
void test() throws Exception {
try {
run();
} catch (Ex1 | Ex2 e) {
throw e.getCause() != null ? new RuntimeException() : e;
}
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -89,6 +89,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
public void testNumericLiterals() { doTest(false, false); }
public void testMultiCatch() { doTest(false, false); }
public void testMultiCatchRethrowConditional() { doTest(false, false); }
public void testTryWithResources() { doTest(false, false); }
public void testTryWithResourcesWarn() { doTest(true, false, new DefUseInspection()); }
public void testSafeVarargsApplicability() { doTest(true, false); }