From e40f11ec526cd73dfc6662cd53fc484fc8b17870 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 20 Aug 2018 14:38:04 +0300 Subject: [PATCH] Improve diagnostics for contract-calls when not lambda-literal passed --- .../contracts/parsing/PsiContractParserDispatcher.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/contracts/parsing/PsiContractParserDispatcher.kt b/compiler/frontend/src/org/jetbrains/kotlin/contracts/parsing/PsiContractParserDispatcher.kt index 9dea11baa6a..9b7cdcd19fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/contracts/parsing/PsiContractParserDispatcher.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/contracts/parsing/PsiContractParserDispatcher.kt @@ -56,7 +56,14 @@ internal class PsiContractParserDispatcher( // Must be non-null because of checks in 'checkContractAndRecordIfPresent', but actually is not, see EA-124365 val resolvedCall = callContext.contractCallExpression.getResolvedCall(callContext.bindingContext) ?: return null - val lambda = resolvedCall.firstArgumentAsExpressionOrNull() as? KtLambdaExpression ?: return null + val firstArgumentExpression = resolvedCall.firstArgumentAsExpressionOrNull() + val lambda = if (firstArgumentExpression is KtLambdaExpression) { + firstArgumentExpression + } else { + val reportOn = firstArgumentExpression ?: callContext.contractCallExpression + collector.badDescription("first argument of 'contract'-call should be a lambda expression", reportOn) + return null + } val effects = lambda.bodyExpression?.statements?.mapNotNull { parseEffect(it) } ?: return null