Minor. Replace manual checkCoroutineBuilderCall with BuilderFunctionsCallChecker

This commit is contained in:
Denis Zharkov
2016-06-09 13:54:40 +03:00
parent 1b82e43d76
commit 072abe89cd
3 changed files with 15 additions and 15 deletions
@@ -68,7 +68,8 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf(
private val DEFAULT_CALL_CHECKERS = listOf(CapturingInClosureChecker(), InlineCheckerWrapper(), ReifiedTypeParameterSubstitutionChecker(), private val DEFAULT_CALL_CHECKERS = listOf(CapturingInClosureChecker(), InlineCheckerWrapper(), ReifiedTypeParameterSubstitutionChecker(),
SafeCallChecker(), InvokeConventionChecker(), CallReturnsArrayOfNothingChecker(), SafeCallChecker(), InvokeConventionChecker(), CallReturnsArrayOfNothingChecker(),
ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, CoroutineSuspendCallChecker) ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, CoroutineSuspendCallChecker,
BuilderFunctionsCallChecker)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>() private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_VALIDATORS = listOf(DeprecatedSymbolValidator(), OperatorValidator(), InfixValidator()) private val DEFAULT_VALIDATORS = listOf(DeprecatedSymbolValidator(), OperatorValidator(), InfixValidator())
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getEffectiveExpectedType import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getEffectiveExpectedType
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInvokeCallOnVariable import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInvokeCallOnVariable
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.checkCoroutineBuilderCall
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CallPosition import org.jetbrains.kotlin.resolve.calls.context.CallPosition
@@ -95,7 +94,6 @@ class CallCompleter(
symbolUsageValidator.validateCall(resolvedCall, resolvedCall.resultingDescriptor, context.trace, element!!) symbolUsageValidator.validateCall(resolvedCall, resolvedCall.resultingDescriptor, context.trace, element!!)
resolveHandleResultCallForCoroutineLambdaExpressions(context, resolvedCall) resolveHandleResultCallForCoroutineLambdaExpressions(context, resolvedCall)
checkCoroutineBuilderCall(resolvedCall, context, languageFeatureSettings)
} }
if (results.isSingleResult && results.resultingCall.status.isSuccess) { if (results.isSingleResult && results.resultingCall.status.isSuccess) {
@@ -40,17 +40,18 @@ object CoroutineSuspendCallChecker : SimpleCallChecker {
} }
} }
// It can't be another CallChecker implementation because of 3rd parameter object BuilderFunctionsCallChecker : CallChecker {
fun checkCoroutineBuilderCall( override fun check(
resolvedCall: ResolvedCall<*>, resolvedCall: ResolvedCall<*>,
context: BasicCallResolutionContext, context: BasicCallResolutionContext,
languageFeatureSettings: LanguageFeatureSettings languageFeatureSettings: LanguageFeatureSettings
) { ) {
val descriptor = resolvedCall.candidateDescriptor as? FunctionDescriptor ?: return val descriptor = resolvedCall.candidateDescriptor as? FunctionDescriptor ?: return
if (descriptor.valueParameters.any { it.isCoroutine } if (descriptor.valueParameters.any { it.isCoroutine }
&& !languageFeatureSettings.supportsFeature(LanguageFeature.Coroutines)) { && !languageFeatureSettings.supportsFeature(LanguageFeature.Coroutines)) {
context.trace.report( context.trace.report(
Errors.UNSUPPORTED_FEATURE.on( Errors.UNSUPPORTED_FEATURE.on(
resolvedCall.call.calleeExpression ?: resolvedCall.call.callElement, LanguageFeature.Coroutines)) resolvedCall.call.calleeExpression ?: resolvedCall.call.callElement, LanguageFeature.Coroutines))
}
} }
} }