SLC: add nullity annotation when force-boxing return type
^KT-57579 Fixed
This commit is contained in:
committed by
Space Team
parent
487847bedc
commit
37876313c9
+17
-7
@@ -211,7 +211,11 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
|
||||
if (nullabilityApplicable) {
|
||||
withPropertySymbol { propertySymbol ->
|
||||
if (propertySymbol.isLateInit) NullabilityType.NotNull else getTypeNullability(propertySymbol.returnType)
|
||||
when {
|
||||
propertySymbol.isLateInit -> NullabilityType.NotNull
|
||||
forceBoxedReturnType(propertySymbol) -> NullabilityType.NotNull
|
||||
else -> getTypeNullability(propertySymbol.returnType)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NullabilityType.Unknown
|
||||
@@ -238,18 +242,24 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
|
||||
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, containingPropertyDeclaration)
|
||||
|
||||
context(KtAnalysisSession)
|
||||
private fun forceBoxedReturnType(propertySymbol: KtPropertySymbol): Boolean {
|
||||
return propertySymbol.returnType.isPrimitive &&
|
||||
propertySymbol.getAllOverriddenSymbols().any { overriddenSymbol ->
|
||||
!overriddenSymbol.returnType.isPrimitive
|
||||
}
|
||||
}
|
||||
|
||||
private val _returnedType: PsiType by lazyPub {
|
||||
if (!isGetter) return@lazyPub PsiType.VOID
|
||||
|
||||
withPropertySymbol { propertySymbol ->
|
||||
val ktType = propertySymbol.returnType
|
||||
|
||||
val forceBoxedReturnType = ktType.isPrimitive &&
|
||||
propertySymbol.getAllOverriddenSymbols().any { overriddenSymbol ->
|
||||
!overriddenSymbol.returnType.isPrimitive
|
||||
}
|
||||
|
||||
val typeMappingMode = if (forceBoxedReturnType) KtTypeMappingMode.RETURN_TYPE_BOXED else KtTypeMappingMode.RETURN_TYPE
|
||||
val typeMappingMode = if (forceBoxedReturnType(propertySymbol))
|
||||
KtTypeMappingMode.RETURN_TYPE_BOXED
|
||||
else
|
||||
KtTypeMappingMode.RETURN_TYPE
|
||||
|
||||
ktType.asPsiType(
|
||||
this@SymbolLightAccessorMethod,
|
||||
|
||||
+26
-18
@@ -154,11 +154,17 @@ internal class SymbolLightSimpleMethod(
|
||||
NullabilityType.Unknown
|
||||
} else {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
if (functionSymbol.isSuspend) { // Any?
|
||||
NullabilityType.Nullable
|
||||
} else {
|
||||
val returnType = functionSymbol.returnType
|
||||
if (returnType.isVoidType) NullabilityType.Unknown else getTypeNullability(returnType)
|
||||
when {
|
||||
functionSymbol.isSuspend -> { // Any?
|
||||
NullabilityType.Nullable
|
||||
}
|
||||
forceBoxedReturnType(functionSymbol) -> {
|
||||
NullabilityType.NotNull
|
||||
}
|
||||
else -> {
|
||||
val returnType = functionSymbol.returnType
|
||||
if (returnType.isVoidType) NullabilityType.Unknown else getTypeNullability(returnType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,19 +186,18 @@ internal class SymbolLightSimpleMethod(
|
||||
}
|
||||
|
||||
// Inspired by KotlinTypeMapper#forceBoxedReturnType
|
||||
private fun forceBoxedReturnType(): Boolean {
|
||||
return withFunctionSymbol { functionSymbol ->
|
||||
val returnType = functionSymbol.returnType
|
||||
// 'invoke' methods for lambdas, function literals, and callable references
|
||||
// implicitly override generic 'invoke' from a corresponding base class.
|
||||
if (functionSymbol.isBuiltinFunctionInvoke && returnType.isInlineClassType)
|
||||
return@withFunctionSymbol true
|
||||
context(KtAnalysisSession)
|
||||
private fun forceBoxedReturnType(functionSymbol: KtFunctionSymbol): Boolean {
|
||||
val returnType = functionSymbol.returnType
|
||||
// 'invoke' methods for lambdas, function literals, and callable references
|
||||
// implicitly override generic 'invoke' from a corresponding base class.
|
||||
if (functionSymbol.isBuiltinFunctionInvoke && returnType.isInlineClassType)
|
||||
return true
|
||||
|
||||
returnType.isPrimitive &&
|
||||
functionSymbol.getAllOverriddenSymbols().any { overriddenSymbol ->
|
||||
!overriddenSymbol.returnType.isPrimitive
|
||||
}
|
||||
}
|
||||
return returnType.isPrimitive &&
|
||||
functionSymbol.getAllOverriddenSymbols().any { overriddenSymbol ->
|
||||
!overriddenSymbol.returnType.isPrimitive
|
||||
}
|
||||
}
|
||||
|
||||
private val KtType.isInlineClassType: Boolean
|
||||
@@ -208,7 +213,10 @@ internal class SymbolLightSimpleMethod(
|
||||
functionSymbol.returnType.takeUnless { it.isVoidType } ?: return@withFunctionSymbol PsiType.VOID
|
||||
}
|
||||
|
||||
val typeMappingMode = if (forceBoxedReturnType()) KtTypeMappingMode.RETURN_TYPE_BOXED else KtTypeMappingMode.RETURN_TYPE
|
||||
val typeMappingMode = if (forceBoxedReturnType(functionSymbol))
|
||||
KtTypeMappingMode.RETURN_TYPE_BOXED
|
||||
else
|
||||
KtTypeMappingMode.RETURN_TYPE
|
||||
|
||||
ktType.asPsiTypeElement(
|
||||
this@SymbolLightSimpleMethod,
|
||||
|
||||
+2
@@ -2,9 +2,11 @@ public final class C /* C*/ implements Tr {
|
||||
private final int v;
|
||||
|
||||
@java.lang.Override()
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public java.lang.Integer foo();// foo()
|
||||
|
||||
@java.lang.Override()
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public java.lang.Integer getV();// getV()
|
||||
|
||||
public C();// .ctor()
|
||||
|
||||
Reference in New Issue
Block a user