Fixed inline when multiple implicit receivers exist
#KT-17776 Fixed #KT-17266 Fixed
This commit is contained in:
@@ -91,8 +91,8 @@ class CodeInliner<TCallElement : KtElement>(
|
||||
|
||||
if (receiver == null) {
|
||||
val receiverValue = if (descriptor.isExtension) resolvedCall.extensionReceiver else resolvedCall.dispatchReceiver
|
||||
val resolutionScope = elementToBeReplaced.getResolutionScope(bindingContext, elementToBeReplaced.getResolutionFacade())
|
||||
if (receiverValue is ImplicitReceiver) {
|
||||
val resolutionScope = elementToBeReplaced.getResolutionScope(bindingContext, elementToBeReplaced.getResolutionFacade())
|
||||
receiver = receiverValue.asExpression(resolutionScope, psiFactory)
|
||||
receiverType = receiverValue.type
|
||||
}
|
||||
@@ -100,14 +100,11 @@ class CodeInliner<TCallElement : KtElement>(
|
||||
|
||||
receiver?.mark(RECEIVER_VALUE_KEY)
|
||||
|
||||
//TODO: this@
|
||||
for (thisExpression in codeToInline.collectDescendantsOfType<KtThisExpression>()) {
|
||||
if (receiver != null) {
|
||||
// for this@ClassName we have only option to keep it as is (although it's sometimes incorrect but we have no other options)
|
||||
if (thisExpression.labelQualifier == null && receiver != null) {
|
||||
codeToInline.replaceExpression(thisExpression, receiver)
|
||||
}
|
||||
else {
|
||||
thisExpression.mark(RECEIVER_VALUE_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
val introduceValuesForParameters = processValueParameterUsages(callableForParameters)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// "Replace with 'newFun(this)'" "true"
|
||||
// ERROR: Unresolved reference: newFun
|
||||
// ERROR: Unresolved reference: @Outer
|
||||
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// "Replace with 'newFun(this)'" "true"
|
||||
// ERROR: Unresolved reference: newFun
|
||||
// ERROR: Unresolved reference: @Outer
|
||||
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
@@ -11,5 +11,5 @@ class Outer {
|
||||
}
|
||||
|
||||
fun foo(inner: Outer.Inner) {
|
||||
inner.newFun(inner)
|
||||
this@Outer.newFun(inner)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class Extended { val extMember = 1 }
|
||||
|
||||
class ExtContext {
|
||||
val ctxMember = 2
|
||||
|
||||
fun Extended.<caret>extend() = extMember + ctxMember
|
||||
|
||||
fun call(extended: Extended) {
|
||||
val v = extended.extend()
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Extended { val extMember = 1 }
|
||||
|
||||
class ExtContext {
|
||||
val ctxMember = 2
|
||||
|
||||
fun call(extended: Extended) {
|
||||
val v = extended.extMember + ctxMember
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class Test {
|
||||
inner class Inner {
|
||||
fun bar() {
|
||||
listOf("").forEach {
|
||||
<caret>foo(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(v: String) {
|
||||
bizz(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun bizz(v:String) {
|
||||
v.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
inner class Inner {
|
||||
fun bar() {
|
||||
listOf("").forEach {
|
||||
bizz(it)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun bizz(v:String) {
|
||||
v.toString()
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,12 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionAndDispatchReceivers.kt")
|
||||
public void testExtensionAndDispatchReceivers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/ExtensionAndDispatchReceivers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("InStringTemplates.kt")
|
||||
public void testInStringTemplates() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/InStringTemplates.kt");
|
||||
@@ -74,6 +80,12 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OuterClassReceiver.kt")
|
||||
public void testOuterClassReceiver() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/OuterClassReceiver.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Reference.kt")
|
||||
public void testReference() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/Reference.kt");
|
||||
|
||||
Reference in New Issue
Block a user