Skip to content

Commit

Permalink
Fix class cast exception
Browse files Browse the repository at this point in the history
  • Loading branch information
raniejade committed Dec 3, 2016
1 parent 2ccab27 commit 423dff3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugin/src/main/kotlin/org/jetbrains/spek/idea/SpekUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 423dff3

Please sign in to comment.