Fix search of correspondent call expression by element (KT-11234)

getStrictParentOfType() looks for nearest parent of given type

In complex expressions like:

SamConversion.doAction({
  inlineCall {
    {
      // here <--
    }()
  }
})

doAction was found twice, while inlineCall was skipped.

See code:
// call(param, { <it> })
lambdaExpression?.typedParent<KtValueArgument>()?.typedParent<KtValueArgumentList>()?.typedParent<KtCallExpression>() ?:

// call { <it> }
lambdaExpression?.typedParent<KtLambdaArgument>()?.typedParent<KtCallExpression>()

 #KT-11234 Fixed
This commit is contained in:
Nikolay Krasko
2017-03-03 16:02:39 +03:00
parent b240ae791c
commit 2719016539
7 changed files with 88 additions and 1 deletions
@@ -0,0 +1,11 @@
package forTests;
public class SamConversion {
public interface Runnable {
public abstract void run();
}
public static void doAction(Runnable runnable) {
runnable.run();
}
}
@@ -0,0 +1,26 @@
package stopInInlineUnderOtherCall
fun main(args: Array<String>) {
val a = 1
nonInline(
{
inlineCall {
{
//Breakpoint!
foo(a)
}()
}
}
)
}
fun foo(a: Any) {}
fun nonInline(f: () -> Unit) {
f()
}
inline fun inlineCall(f: () -> Unit) {
f()
}
@@ -0,0 +1,22 @@
package stopInInlineUnderSamConversion
import forTests.SamConversion
fun main(args: Array<String>) {
val a = 1
SamConversion.doAction({
inlineCall {
{
//Breakpoint!
foo(a)
}()
}
})
}
fun foo(a: Any) {}
inline fun inlineCall(f: () -> Unit) {
f()
}