Replace resolution error for suspend-conversion with call checker error

This commit is contained in:
Mikhail Zarechenskiy
2020-06-01 01:52:56 +03:00
parent eaeaf3c8a3
commit a5203428a4
18 changed files with 265 additions and 22 deletions
@@ -49,7 +49,7 @@ private val DEFAULT_CALL_CHECKERS = listOf(
PrimitiveNumericComparisonCallChecker, LambdaWithSuspendModifierCallChecker,
UselessElvisCallChecker(), ResultTypeWithNullableOperatorsChecker(), NullableVarargArgumentCallChecker,
NamedFunAsExpressionChecker, ContractNotAllowedCallChecker, ReifiedTypeParameterSubstitutionChecker(),
MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker,
MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker, SuspendConversionCallChecker
)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallArgument
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl
import org.jetbrains.kotlin.resolve.calls.tower.psiCallArgument
import org.jetbrains.kotlin.resolve.calls.tower.psiExpression
object SuspendConversionCallChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
if (resolvedCall !is NewResolvedCallImpl<*>) return
if (context.languageVersionSettings.supportsFeature(LanguageFeature.SuspendConversion)) return
val argumentsWithSuspendConversion = resolvedCall.resolvedCallAtom.argumentsWithSuspendConversion
for (argumentWithSuspendConversion in argumentsWithSuspendConversion.keys) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
argumentWithSuspendConversion.psiCallArgument.valueArgument.asElement(),
LanguageFeature.SuspendConversion to context.languageVersionSettings
)
)
}
for ((parameter, argument) in resolvedCall.argumentMappingByOriginal) {
if (!parameter.type.isSuspendFunctionType) continue
if (argument !is ResolvedCallArgument.SimpleArgument) continue
val callArgument = argument.callArgument
if (callArgument !is CallableReferenceKotlinCallArgument) continue
val callableReferenceExpression = callArgument.psiExpression as? KtCallableReferenceExpression ?: continue
val argumentCall = callableReferenceExpression.callableReference.getResolvedCall(context.trace.bindingContext) ?: continue
val target = argumentCall.resultingDescriptor as? FunctionDescriptor ?: continue
if (!target.isSuspend) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
callableReferenceExpression,
LanguageFeature.SuspendConversion to context.languageVersionSettings
)
)
}
}
}
}