Check type parameter bounds by java nullability annotations not only in basic resolution context

^KT-47920 Fixed
This commit is contained in:
Victor Petukhov
2021-07-27 13:24:54 +03:00
committed by teamcityserver
parent 20d50cfee7
commit c5d783596d
7 changed files with 37 additions and 5 deletions
@@ -128,13 +128,16 @@ class JavaNullabilityChecker(val upperBoundChecker: UpperBoundChecker) : Additio
upperBoundChecker.checkBoundsOfExpandedTypeAlias(expressionType.expandedType, expression, c.trace)
}
if (c !is BasicCallResolutionContext || upperBoundChecker !is WarningAwareUpperBoundChecker) return
if (upperBoundChecker !is WarningAwareUpperBoundChecker) return
val resolvedCall = c.trace.bindingContext[BindingContext.RESOLVED_CALL, c.call] ?: return
val call = (c as? BasicCallResolutionContext)?.call
?: c.trace.bindingContext[BindingContext.CALL, (expression as? KtCallExpression)?.calleeExpression]
?: return
val resolvedCall = c.trace.bindingContext[BindingContext.RESOLVED_CALL, call] ?: return
for ((typeParameter, typeArgument) in resolvedCall.typeArguments) {
// continue if we don't have explicit type arguments
val typeReference = c.call.typeArguments.getOrNull(typeParameter.index)?.typeReference ?: continue
val typeReference = call.typeArguments.getOrNull(typeParameter.index)?.typeReference ?: continue
upperBoundChecker.checkBounds(
typeReference, typeArgument, typeParameter, TypeSubstitutor.create(typeArgument), c.trace, withOnlyCheckForWarning = true