From 423dff3c690f55db35d180f65770d19095db68e1 Mon Sep 17 00:00:00 2001 From: Ranie Jade Ramiso Date: Sat, 3 Dec 2016 11:46:06 +0800 Subject: [PATCH] Fix class cast exception --- plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt b/plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt index 954d9c9..7bebd66 100644 --- a/plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt +++ b/plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt @@ -50,7 +50,7 @@ object SpekUtils { val calleeExpression = callExpression.calleeExpression!! as KtNameReferenceExpression val resolved = calleeExpression.mainReference.resolve() - if (resolved != null && resolved is KtNamedFunction) { + if (resolved != null && resolved is KtNamedFunction && isContainedWithinLambda(callExpression)) { if (lambda != null && parameters.size == 2 && isDslExtension(resolved)) { val desc = parameters.first().children.firstOrNull() if (desc != null && desc is KtStringTemplateExpression) { @@ -150,6 +150,8 @@ object SpekUtils { return callExpression.parent.parent.parent as KtLambdaExpression } + fun isContainedWithinLambda(callExpression: KtCallExpression) = callExpression.parent.parent.parent is KtLambdaExpression + fun isDslExtension(function: KtNamedFunction): Boolean { val receiverTypeReference = function.receiverTypeReference if (receiverTypeReference != null) {