From 97d5bbf1c2bcf8081a92285aa4d83b2465fd437d Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 6 Dec 2016 17:31:02 +0300 Subject: [PATCH] toDelegateFor: JVM BE implementation --- .../kotlin/codegen/MemberCodegen.java | 29 ++++++- .../kotlin/codegen/PropertyCodegen.java | 79 +++++++++++++------ .../toDelegateFor/evaluationOrder.kt | 26 ++++++ .../toDelegateFor/inClass.kt | 30 +++++++ .../toDelegateFor/inlineToDelegateFor.kt | 26 ++++++ .../toDelegateFor/jvmStaticInObject.kt | 31 ++++++++ .../toDelegateFor/memberExtension.kt | 16 ++++ .../toDelegateFor/evaluationOrder.txt | 16 ++++ .../toDelegateFor/inClass.txt | 21 +++++ .../toDelegateFor/inlineToDelegateFor.txt | 16 ++++ .../toDelegateFor/jvmStaticInObject.txt | 26 ++++++ .../toDelegateFor/memberExtension.txt | 25 ++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 30 +++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 30 +++++++ ...LightAnalysisModeCodegenTestGenerated.java | 30 +++++++ .../semantics/JsCodegenBoxTestGenerated.java | 60 ++++++++++++++ 16 files changed, 464 insertions(+), 27 deletions(-) create mode 100644 compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt create mode 100644 compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt create mode 100644 compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt create mode 100644 compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt create mode 100644 compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/evaluationOrder.txt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inClass.txt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inlineToDelegateFor.txt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/jvmStaticInObject.txt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/memberExtension.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index ea1063d40e5..3ee9c9f229e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.codegen.inline.*; import org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; -import org.jetbrains.kotlin.config.LanguageVersionSettings; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; @@ -46,6 +45,7 @@ import org.jetbrains.kotlin.psi.synthetics.SyntheticClassOrObjectDescriptor; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingContextUtils; import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.constants.ConstantValue; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.jvm.AsmTypes; @@ -58,6 +58,7 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.storage.NotNullLazyValue; import org.jetbrains.kotlin.types.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; +import org.jetbrains.kotlin.util.OperatorNameConventions; import org.jetbrains.org.objectweb.asm.*; import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.org.objectweb.asm.commons.Method; @@ -66,6 +67,7 @@ import java.util.*; import static org.jetbrains.kotlin.codegen.AsmUtil.*; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED; +import static org.jetbrains.kotlin.resolve.BindingContext.TO_DELEGATE_FOR_RESOLVED_CALL; import static org.jetbrains.kotlin.resolve.BindingContext.TYPE_ALIAS; import static org.jetbrains.kotlin.resolve.BindingContext.VARIABLE; import static org.jetbrains.kotlin.resolve.DescriptorUtils.*; @@ -462,10 +464,29 @@ public abstract class MemberCodegen toDelegateForResolvedCall = bindingContext.get(TO_DELEGATE_FOR_RESOLVED_CALL, propertyDescriptor); + if (toDelegateForResolvedCall == null) { + propValue.store(codegen.gen(initializer), codegen.v); + return; + } + + StackValue toDelegateForReceiver = codegen.gen(initializer); + + int indexOfDelegatedProperty = PropertyCodegen.indexOfDelegatedProperty(property); + + List arguments = toDelegateForResolvedCall.getCall().getValueArguments(); + assert arguments.size() == 2 : + "Resolved call for '" + OperatorNameConventions.TO_DELEGATE_FOR.asString() + "' should have exactly 2 value parameters"; + codegen.tempVariables.put(arguments.get(0).asElement(), StackValue.LOCAL_0); + + StackValue delegateValue = PropertyCodegen.invokeDelegatedPropertyConventionMethodWithReceiver( + codegen, typeMapper, toDelegateForResolvedCall, indexOfDelegatedProperty, 1, toDelegateForReceiver); + + propValue.store(delegateValue, codegen.v); - propValue.store(codegen.gen(initializer), codegen.v); } protected boolean shouldInitializeProperty(@NotNull KtProperty property) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index eda06a9ef65..50d01b6a6d0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations; import org.jetbrains.kotlin.codegen.context.*; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; -import org.jetbrains.kotlin.config.LanguageVersionSettings; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotated; import org.jetbrains.kotlin.descriptors.annotations.AnnotationSplitter; @@ -367,16 +366,33 @@ public class PropertyCodegen { @NotNull PropertyDescriptor propertyDescriptor, @NotNull Annotations annotations ) { - KtExpression delegateExpression = p.getDelegateExpression(); - KotlinType delegateType = delegateExpression != null ? bindingContext.getType(p.getDelegateExpression()) : null; - if (delegateType == null) { - // If delegate expression is unresolved reference - delegateType = ErrorUtils.createErrorType("Delegate type"); - } + KotlinType delegateType = getDelegateTypeForProperty(p, propertyDescriptor); generateBackingField(p, propertyDescriptor, true, delegateType, null, annotations); } + @NotNull + private KotlinType getDelegateTypeForProperty(@NotNull KtProperty p, @NotNull PropertyDescriptor propertyDescriptor) { + KotlinType delegateType = null; + + ResolvedCall toDelegateForResolvedCall = + bindingContext.get(BindingContext.TO_DELEGATE_FOR_RESOLVED_CALL, propertyDescriptor); + KtExpression delegateExpression = p.getDelegateExpression(); + + if (toDelegateForResolvedCall != null) { + delegateType = toDelegateForResolvedCall.getResultingDescriptor().getReturnType(); + } + else if (delegateExpression != null) { + delegateType = bindingContext.getType(delegateExpression); + } + + if (delegateType == null) { + // Delegation convention is unresolved + delegateType = ErrorUtils.createErrorType("Delegate type"); + } + return delegateType; + } + private void generateBackingFieldAccess( @NotNull KtNamedDeclaration p, @NotNull PropertyDescriptor propertyDescriptor, @@ -519,20 +535,22 @@ public class PropertyCodegen { final int indexInPropertyMetadataArray, int propertyMetadataArgumentIndex ) { - CodegenContext ownerContext = codegen.getContext().getClassOrPackageParentContext(); - final Type owner; - if (ownerContext instanceof ClassContext) { - owner = typeMapper.mapClass(((ClassContext) ownerContext).getContextDescriptor()); - } - else if (ownerContext instanceof PackageContext) { - owner = ((PackageContext) ownerContext).getPackagePartType(); - } - else if (ownerContext instanceof MultifileClassContextBase) { - owner = ((MultifileClassContextBase) ownerContext).getFilePartType(); - } - else { - throw new UnsupportedOperationException("Unknown context: " + ownerContext); - } + StackValue.Property receiver = codegen.intermediateValueForProperty(propertyDescriptor, true, null, StackValue.LOCAL_0); + return invokeDelegatedPropertyConventionMethodWithReceiver( + codegen, typeMapper, resolvedCall, indexInPropertyMetadataArray, propertyMetadataArgumentIndex, + receiver + ); + } + + public static StackValue invokeDelegatedPropertyConventionMethodWithReceiver( + @NotNull ExpressionCodegen codegen, + @NotNull KotlinTypeMapper typeMapper, + @NotNull ResolvedCall resolvedCall, + final int indexInPropertyMetadataArray, + int propertyMetadataArgumentIndex, + @Nullable StackValue receiver + ) { + final Type owner = getDelegatedPropertyMetadataOwner(codegen, typeMapper); codegen.tempVariables.put( resolvedCall.getCall().getValueArguments().get(propertyMetadataArgumentIndex).asElement(), @@ -549,8 +567,23 @@ public class PropertyCodegen { } ); - StackValue delegatedProperty = codegen.intermediateValueForProperty(propertyDescriptor, true, null, StackValue.LOCAL_0); - return codegen.invokeFunction(resolvedCall, delegatedProperty); + return codegen.invokeFunction(resolvedCall, receiver); + } + + private static Type getDelegatedPropertyMetadataOwner(@NotNull ExpressionCodegen codegen, @NotNull KotlinTypeMapper typeMapper) { + CodegenContext ownerContext = codegen.getContext().getClassOrPackageParentContext(); + if (ownerContext instanceof ClassContext) { + return typeMapper.mapClass(((ClassContext) ownerContext).getContextDescriptor()); + } + else if (ownerContext instanceof PackageContext) { + return ((PackageContext) ownerContext).getPackagePartType(); + } + else if (ownerContext instanceof MultifileClassContextBase) { + return ((MultifileClassContextBase) ownerContext).getFilePartType(); + } + else { + throw new UnsupportedOperationException("Unknown context: " + ownerContext); + } } private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { diff --git a/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt new file mode 100644 index 00000000000..8702a6f5323 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt @@ -0,0 +1,26 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +import kotlin.test.* + +var log: String = "" + +inline fun runLogged(entry: String, action: () -> T): T { + log += entry + return action() +} + +operator fun String.toDelegateFor(host: Any?, p: Any): String = + runLogged("tdf($this);") { this } + +operator fun String.getValue(receiver: Any?, p: Any): String = + runLogged("get($this);") { this } + +val testO by runLogged("O;") { "O" } +val testK by runLogged("K;") { "K" } +val testOK = runLogged("OK;") { testO + testK } + +fun box(): String { + assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log) + return testOK +} diff --git a/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt new file mode 100644 index 00000000000..96d3e9c0d40 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt @@ -0,0 +1,30 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +import kotlin.test.* + +var log: String = "" + +inline fun runLogged(entry: String, action: () -> T): T { + log += entry + return action() +} + +operator fun String.toDelegateFor(host: Any?, p: Any): String = + runLogged("tdf($this);") { this } + +operator fun String.getValue(receiver: Any?, p: Any): String = + runLogged("get($this);") { this } + +class Test { + val testO by runLogged("O;") { "O" } + val testK by runLogged("K;") { "K" } + val testOK = runLogged("OK;") { testO + testK } +} + +fun box(): String { + assertEquals("", log) + val test = Test() + assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log) + return test.testOK +} diff --git a/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt new file mode 100644 index 00000000000..6c518516df5 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt @@ -0,0 +1,26 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +import kotlin.test.* + +var log: String = "" + +inline fun runLogged(entry: String, action: () -> T): T { + log += entry + return action() +} + +inline operator fun String.toDelegateFor(host: Any?, p: Any): String = + runLogged("tdf($this);") { this } + +operator fun String.getValue(receiver: Any?, p: Any): String = + runLogged("get($this);") { this } + +val testO by runLogged("O;") { "O" } +val testK by runLogged("K;") { "K" } +val testOK = runLogged("OK;") { testO + testK } + +fun box(): String { + assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log) + return testOK +} diff --git a/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt new file mode 100644 index 00000000000..09b252f78a7 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt @@ -0,0 +1,31 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +import kotlin.test.* + +var log: String = "" + +inline fun runLogged(entry: String, action: () -> T): T { + log += entry + return action() +} + +operator fun String.toDelegateFor(host: Any?, p: Any): String = + runLogged("tdf($this);") { this } + +operator fun String.getValue(receiver: Any?, p: Any): String = + runLogged("get($this);") { this } + +object Test { + fun foo() {} + @JvmStatic val testO by runLogged("O;") { "O" } + @JvmStatic val testK by runLogged("K;") { "K" } + @JvmStatic val testOK = runLogged("OK;") { testO + testK } +} + +fun box(): String { + assertEquals("", log) + Test.foo() + assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log) + return Test.testOK +} diff --git a/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt new file mode 100644 index 00000000000..93b933cc36c --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt @@ -0,0 +1,16 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +object Host { + class StringDelegate(val s: String) { + operator fun getValue(receiver: String, p: Any) = receiver + s + } + + operator fun String.toDelegateFor(host: Any?, p: Any) = StringDelegate(this) + + val String.plusK by "K" + + val ok = "O".plusK +} + +fun box(): String = Host.ok \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/evaluationOrder.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/evaluationOrder.txt new file mode 100644 index 00000000000..979c15e8c82 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/evaluationOrder.txt @@ -0,0 +1,16 @@ +public final class EvaluationOrderKt { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + private static @org.jetbrains.annotations.NotNull field log: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testK$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testO$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testOK: java.lang.String + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestK(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestO(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestOK(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String + public final static method runLogged(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function0): java.lang.Object + public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final static @org.jetbrains.annotations.NotNull method toDelegateFor(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inClass.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inClass.txt new file mode 100644 index 00000000000..59fc529fb06 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inClass.txt @@ -0,0 +1,21 @@ +public final class InClassKt { + private static @org.jetbrains.annotations.NotNull field log: java.lang.String + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String + public final static method runLogged(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function0): java.lang.Object + public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final static @org.jetbrains.annotations.NotNull method toDelegateFor(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String +} + + +public final class Test { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + private final @org.jetbrains.annotations.NotNull field testK$delegate: java.lang.String + private final @org.jetbrains.annotations.NotNull field testO$delegate: java.lang.String + private final @org.jetbrains.annotations.NotNull field testOK: java.lang.String + public method (): void + public final @org.jetbrains.annotations.NotNull method getTestK(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getTestO(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getTestOK(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inlineToDelegateFor.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inlineToDelegateFor.txt new file mode 100644 index 00000000000..ae1ddb13606 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/inlineToDelegateFor.txt @@ -0,0 +1,16 @@ +public final class InlineToDelegateForKt { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + private static @org.jetbrains.annotations.NotNull field log: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testK$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testO$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testOK: java.lang.String + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestK(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestO(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestOK(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String + public final static method runLogged(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function0): java.lang.Object + public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final static @org.jetbrains.annotations.NotNull method toDelegateFor(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/jvmStaticInObject.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/jvmStaticInObject.txt new file mode 100644 index 00000000000..e2d4e7af8a0 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/jvmStaticInObject.txt @@ -0,0 +1,26 @@ +public final class JvmStaticInObjectKt { + private static @org.jetbrains.annotations.NotNull field log: java.lang.String + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String + public final static method runLogged(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function0): java.lang.Object + public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final static @org.jetbrains.annotations.NotNull method toDelegateFor(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): java.lang.String +} + + +public final class Test { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + public final static field INSTANCE: Test + private final static @org.jetbrains.annotations.NotNull field testK$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testO$delegate: java.lang.String + private final static @org.jetbrains.annotations.NotNull field testOK: java.lang.String + private method (): void + public final method foo(): void + public final static @org.jetbrains.annotations.NotNull method getTestK(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestO(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getTestOK(): java.lang.String + private synthetic deprecated static @kotlin.jvm.JvmStatic method testK$annotations(): void + private synthetic deprecated static @kotlin.jvm.JvmStatic method testO$annotations(): void + private synthetic deprecated static @kotlin.jvm.JvmStatic method testOK$annotations(): void +} diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/memberExtension.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/memberExtension.txt new file mode 100644 index 00000000000..aef3631fc8d --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/toDelegateFor/memberExtension.txt @@ -0,0 +1,25 @@ +public final class Host { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + public final static field INSTANCE: Host + private final static @org.jetbrains.annotations.NotNull field ok: java.lang.String + private final static @org.jetbrains.annotations.NotNull field plusK$delegate: Host.StringDelegate + inner class Host/StringDelegate + private method (): void + public final @org.jetbrains.annotations.NotNull method getOk(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getPlusK(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String + public final @org.jetbrains.annotations.NotNull method toDelegateFor(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.Object): Host.StringDelegate +} + + +public final static class Host/StringDelegate { + private final @org.jetbrains.annotations.NotNull field s: java.lang.String + inner class Host/StringDelegate + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: java.lang.Object): java.lang.String +} + + +public final class MemberExtensionKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index d701b01ae99..146de6a5f6c 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6001,11 +6001,41 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty/toDelegateFor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("evaluationOrder.kt") + public void testEvaluationOrder() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt"); + doTest(fileName); + } + @TestMetadata("extensionDelegated.kt") public void testExtensionDelegated() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/extensionDelegated.kt"); doTest(fileName); } + + @TestMetadata("inClass.kt") + public void testInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt"); + doTest(fileName); + } + + @TestMetadata("inlineToDelegateFor.kt") + public void testInlineToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("jvmStaticInObject.kt") + public void testJvmStaticInObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt"); + doTest(fileName); + } + + @TestMetadata("memberExtension.kt") + public void testMemberExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index b09361d3853..563f23d142a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6001,11 +6001,41 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty/toDelegateFor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("evaluationOrder.kt") + public void testEvaluationOrder() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt"); + doTest(fileName); + } + @TestMetadata("extensionDelegated.kt") public void testExtensionDelegated() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/extensionDelegated.kt"); doTest(fileName); } + + @TestMetadata("inClass.kt") + public void testInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt"); + doTest(fileName); + } + + @TestMetadata("inlineToDelegateFor.kt") + public void testInlineToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("jvmStaticInObject.kt") + public void testJvmStaticInObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt"); + doTest(fileName); + } + + @TestMetadata("memberExtension.kt") + public void testMemberExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index e9242fdf678..9949466884a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -6001,11 +6001,41 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty/toDelegateFor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("evaluationOrder.kt") + public void testEvaluationOrder() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt"); + doTest(fileName); + } + @TestMetadata("extensionDelegated.kt") public void testExtensionDelegated() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/extensionDelegated.kt"); doTest(fileName); } + + @TestMetadata("inClass.kt") + public void testInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt"); + doTest(fileName); + } + + @TestMetadata("inlineToDelegateFor.kt") + public void testInlineToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("jvmStaticInObject.kt") + public void testJvmStaticInObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt"); + doTest(fileName); + } + + @TestMetadata("memberExtension.kt") + public void testMemberExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt"); + doTest(fileName); + } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index b732f83e594..d1da4d19537 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -6896,11 +6896,71 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty/toDelegateFor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("evaluationOrder.kt") + public void testEvaluationOrder() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/evaluationOrder.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("extensionDelegated.kt") public void testExtensionDelegated() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/extensionDelegated.kt"); doTest(fileName); } + + @TestMetadata("inClass.kt") + public void testInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inClass.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("inlineToDelegateFor.kt") + public void testInlineToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/inlineToDelegateFor.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("jvmStaticInObject.kt") + public void testJvmStaticInObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/jvmStaticInObject.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("memberExtension.kt") + public void testMemberExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/toDelegateFor/memberExtension.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } } }