Control-Flow Analysis: Use PSI to generate pseudocode if nested resolved call is confused with outer one (e.g. a {} when invoke() is missing)
#KT-14500 Fixed
This commit is contained in:
@@ -224,6 +224,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
|
||||
- [`KT-14569`](https://youtrack.jetbrains.com/issue/KT-14569) Convert Property to Function Intention: Search occurrences using progress dialog
|
||||
- [`KT-14501`](https://youtrack.jetbrains.com/issue/KT-14501) Create from Usage: Support array access expressions/binary expressions with type mismatch errors
|
||||
- [`KT-14500`](https://youtrack.jetbrains.com/issue/KT-14500) Create from Usage: Suggest functional type based on the call with lambda argument and unresolved invoke()
|
||||
|
||||
#### Refactorings
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
@@ -1466,7 +1467,10 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
}
|
||||
|
||||
private fun generateCall(callElement: KtElement): Boolean {
|
||||
return checkAndGenerateCall(callElement.getResolvedCall(trace.bindingContext))
|
||||
val resolvedCall = callElement.getResolvedCall(trace.bindingContext)
|
||||
val callElementFromResolvedCall = resolvedCall?.call?.callElement ?: return false
|
||||
if (callElement.isAncestor(callElementFromResolvedCall, true)) return false
|
||||
return checkAndGenerateCall(resolvedCall)
|
||||
}
|
||||
|
||||
private fun checkAndGenerateCall(resolvedCall: ResolvedCall<*>?): Boolean {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
== A ==
|
||||
class A
|
||||
---------------------
|
||||
L0:
|
||||
1 <START>
|
||||
L1:
|
||||
<END> NEXT:[<SINK>]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
== test ==
|
||||
fun test(a: A) {
|
||||
a { }
|
||||
}
|
||||
---------------------
|
||||
L0:
|
||||
1 <START>
|
||||
v(a: A)
|
||||
magic[FAKE_INITIALIZER](a: A) -> <v0>
|
||||
w(a|<v0>)
|
||||
2 mark({ a { } })
|
||||
mark({ })
|
||||
jmp?(L2) NEXT:[r({ }) -> <v1>, d({ })]
|
||||
d({ }) NEXT:[<SINK>]
|
||||
L2 [after local declaration]:
|
||||
r({ }) -> <v1> PREV:[jmp?(L2)]
|
||||
r(a) -> <v2>
|
||||
mark(a { })
|
||||
magic[UNRESOLVED_CALL](a { }|<v1>, <v2>) -> <v3>
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>, d({ })]
|
||||
=====================
|
||||
== anonymous_0 ==
|
||||
{ }
|
||||
---------------------
|
||||
L3:
|
||||
3 <START>
|
||||
4 mark()
|
||||
read (Unit)
|
||||
L4:
|
||||
3 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
@@ -0,0 +1,5 @@
|
||||
class A
|
||||
|
||||
fun test(a: A) {
|
||||
a { }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
== A ==
|
||||
class A
|
||||
---------------------
|
||||
=====================
|
||||
== test ==
|
||||
fun test(a: A) {
|
||||
a { }
|
||||
}
|
||||
---------------------
|
||||
<v0>: A NEW: magic[FAKE_INITIALIZER](a: A) -> <v0>
|
||||
a <v2>: * NEW: r(a) -> <v2>
|
||||
{ } <v1>: * NEW: r({ }) -> <v1>
|
||||
a { } <v3>: * NEW: magic[UNRESOLVED_CALL](a { }|<v1>, <v2>) -> <v3>
|
||||
{ a { } } <v3>: * COPY
|
||||
=====================
|
||||
== anonymous_0 ==
|
||||
{ }
|
||||
---------------------
|
||||
=====================
|
||||
@@ -10,10 +10,12 @@ L0:
|
||||
w(i|<v0>)
|
||||
2 mark({ i() })
|
||||
r(i) -> <v1>
|
||||
mark(i())
|
||||
magic[UNRESOLVED_CALL](i()|<v1>) -> <v2>
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>]
|
||||
1 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
|
||||
@@ -5,6 +5,6 @@ fun foo(i: Int) {
|
||||
---------------------
|
||||
<v0>: Int NEW: magic[FAKE_INITIALIZER](i: Int) -> <v0>
|
||||
i <v1>: * NEW: r(i) -> <v1>
|
||||
i() !<v2>: *
|
||||
{ i() } !<v2>: * COPY
|
||||
=====================
|
||||
i() <v2>: * NEW: magic[UNRESOLVED_CALL](i()|<v1>) -> <v2>
|
||||
{ i() } <v2>: * COPY
|
||||
=====================
|
||||
|
||||
@@ -162,6 +162,12 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/bugs/setWithTypeMismatch.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedInvokeOnResolvedVar.kt")
|
||||
public void testUnresolvedInvokeOnResolvedVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/bugs/unresolvedInvokeOnResolvedVar.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/cfg/controlStructures")
|
||||
|
||||
@@ -164,6 +164,12 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/bugs/setWithTypeMismatch.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedInvokeOnResolvedVar.kt")
|
||||
public void testUnresolvedInvokeOnResolvedVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/bugs/unresolvedInvokeOnResolvedVar.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/cfg/controlStructures")
|
||||
|
||||
Reference in New Issue
Block a user