Properly capture extension receiver for array convention expressions in object constructor
#KT-19389 Fixed
This commit is contained in:
@@ -69,6 +69,8 @@ import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
|||||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
||||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtils2Kt.initDefaultSourceMappingIfNeeded;
|
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtils2Kt.initDefaultSourceMappingIfNeeded;
|
||||||
import static org.jetbrains.kotlin.load.java.JvmAbi.*;
|
import static org.jetbrains.kotlin.load.java.JvmAbi.*;
|
||||||
|
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_GET;
|
||||||
|
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_SET;
|
||||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull;
|
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull;
|
||||||
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
|
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
|
||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||||
@@ -1021,6 +1023,22 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
public void visitSuperExpression(@NotNull KtSuperExpression expression) {
|
public void visitSuperExpression(@NotNull KtSuperExpression expression) {
|
||||||
lookupInContext(ExpressionCodegen.getSuperCallLabelTarget(context, expression));
|
lookupInContext(ExpressionCodegen.getSuperCallLabelTarget(context, expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitArrayAccessExpression(@NotNull KtArrayAccessExpression expression) {
|
||||||
|
ResolvedCall<FunctionDescriptor> resolvedGetCall = bindingContext.get(INDEXED_LVALUE_GET, expression);
|
||||||
|
if (resolvedGetCall != null) {
|
||||||
|
ReceiverValue receiver = resolvedGetCall.getDispatchReceiver();
|
||||||
|
lookupReceiver(receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(INDEXED_LVALUE_SET, expression);
|
||||||
|
if (resolvedSetCall != null) {
|
||||||
|
ReceiverValue receiver = resolvedSetCall.getDispatchReceiver();
|
||||||
|
lookupReceiver(receiver);
|
||||||
|
}
|
||||||
|
super.visitArrayAccessExpression(expression);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (KtDeclaration declaration : myClass.getDeclarations()) {
|
for (KtDeclaration declaration : myClass.getDeclarations()) {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
public fun <T, R> myWith(receiver: T, block: T.() -> R): R {
|
||||||
|
return receiver.block()
|
||||||
|
}
|
||||||
|
|
||||||
|
object Foo2 {
|
||||||
|
operator fun Any?.get(key: String) = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Main {
|
||||||
|
fun bar() = myWith(Foo2) {
|
||||||
|
|
||||||
|
val x = object {
|
||||||
|
val y = 38["Hello!"]
|
||||||
|
}
|
||||||
|
x.y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return Main.bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
var result = "fail"
|
||||||
|
|
||||||
|
public fun <T, R> myWith(receiver: T, block: T.() -> R): R {
|
||||||
|
return receiver.block()
|
||||||
|
}
|
||||||
|
|
||||||
|
object Foo2 {
|
||||||
|
operator fun Any?.get(key: String) = "OK"
|
||||||
|
operator fun Any?.set(key: String, value: String) {
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object Main {
|
||||||
|
fun bar() = myWith(Foo2) {
|
||||||
|
val x = object {
|
||||||
|
init {
|
||||||
|
38["Hello!"] = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return Main.bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
public inline fun <T, R> myWith(receiver: T, block: T.() -> R): R {
|
||||||
|
return receiver.block()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
//NO_CHECK_LAMBDA_INLINING
|
||||||
|
object Foo2 {
|
||||||
|
operator fun Any?.get(key: String) = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Main {
|
||||||
|
fun bar() = myWith(Foo2) {
|
||||||
|
|
||||||
|
val x = object {
|
||||||
|
val y = 38["Hello!"]
|
||||||
|
}
|
||||||
|
x.y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return Main.bar()
|
||||||
|
}
|
||||||
+10
@@ -3736,6 +3736,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389_set.kt")
|
||||||
|
public void testKt19389_set() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389_set.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2151.kt")
|
@TestMetadata("kt2151.kt")
|
||||||
public void testKt2151() throws Exception {
|
public void testKt2151() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
|
|||||||
+5
@@ -186,6 +186,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt19399.kt")
|
@TestMetadata("kt19399.kt")
|
||||||
public void testKt19399() throws Exception {
|
public void testKt19399() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
||||||
|
|||||||
Generated
+5
@@ -186,6 +186,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt19399.kt")
|
@TestMetadata("kt19399.kt")
|
||||||
public void testKt19399() throws Exception {
|
public void testKt19399() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
||||||
|
|||||||
+10
@@ -3736,6 +3736,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389_set.kt")
|
||||||
|
public void testKt19389_set() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389_set.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2151.kt")
|
@TestMetadata("kt2151.kt")
|
||||||
public void testKt2151() throws Exception {
|
public void testKt2151() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
|
|||||||
+10
@@ -3736,6 +3736,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389_set.kt")
|
||||||
|
public void testKt19389_set() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389_set.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2151.kt")
|
@TestMetadata("kt2151.kt")
|
||||||
public void testKt2151() throws Exception {
|
public void testKt2151() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
|
|||||||
+5
@@ -186,6 +186,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
|||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt17972_super3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt19399.kt")
|
@TestMetadata("kt19399.kt")
|
||||||
public void testKt19399() throws Exception {
|
public void testKt19399() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
runTest("compiler/testData/codegen/boxInline/anonymousObject/kt19399.kt");
|
||||||
|
|||||||
+10
@@ -3136,6 +3136,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389_set.kt")
|
||||||
|
public void testKt19389_set() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389_set.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2151.kt")
|
@TestMetadata("kt2151.kt")
|
||||||
public void testKt2151() throws Exception {
|
public void testKt2151() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
|
|||||||
+10
@@ -3136,6 +3136,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
runTest("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389.kt")
|
||||||
|
public void testKt19389() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19389_set.kt")
|
||||||
|
public void testKt19389_set() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/kt19389_set.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2151.kt")
|
@TestMetadata("kt2151.kt")
|
||||||
public void testKt2151() throws Exception {
|
public void testKt2151() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
runTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user