[java-inspections] IDEA-381019 Invalid local variable type inference in JSpecify mode with generic functions

GitOrigin-RevId: 4a99f16a371b9ad909500aadc14031ebcf547149
This commit is contained in:
Mikhail Pyltsin
2025-10-28 19:20:57 +00:00
committed by intellij-monorepo-bot
parent bcf0ff8249
commit 581215e7e9
6 changed files with 78 additions and 2 deletions
@@ -255,6 +255,7 @@ public abstract class PsiClassType extends PsiType implements JvmReferenceType {
/**
* If class-type is created from the explicit reference in the code returns that reference.
* If type is created from `var` keyword, return this keyword
* @return reference which the type is created from. Returns null if not applicable.
*/
@ApiStatus.Experimental
@@ -71,7 +71,8 @@ public final class JavaTypeNullabilityUtil {
private static boolean isLocal(PsiClassType classType) {
PsiElement context = classType.getPsiContext();
return context instanceof PsiJavaCodeReferenceElement &&
//PsiKeyword is used for `var` case
return (context instanceof PsiJavaCodeReferenceElement || PsiUtil.isJavaToken(context, JavaTokenType.VAR_KEYWORD)) &&
context.getParent() instanceof PsiTypeElement &&
context.getParent().getParent() instanceof PsiLocalVariable;
}