JS: fix non-abstract extension properties in interfaces
KT-20994
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
interface I {
|
||||||
|
val String.foo: String
|
||||||
|
get() = this + ";" + bar()
|
||||||
|
|
||||||
|
fun bar(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : I {
|
||||||
|
override fun bar() = "C.bar"
|
||||||
|
|
||||||
|
fun test() = "test".foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val r = C().test()
|
||||||
|
if (r != "test;C.bar") return "fail: $r"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -8591,6 +8591,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonAbstractInInterface.kt")
|
||||||
|
public void testNonAbstractInInterface() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/nonAbstractInInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevel.kt")
|
@TestMetadata("topLevel.kt")
|
||||||
public void testTopLevel() throws Exception {
|
public void testTopLevel() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
||||||
|
|||||||
@@ -8591,6 +8591,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonAbstractInInterface.kt")
|
||||||
|
public void testNonAbstractInInterface() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/nonAbstractInInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevel.kt")
|
@TestMetadata("topLevel.kt")
|
||||||
public void testTopLevel() throws Exception {
|
public void testTopLevel() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
||||||
|
|||||||
@@ -8591,6 +8591,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonAbstractInInterface.kt")
|
||||||
|
public void testNonAbstractInInterface() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/nonAbstractInInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevel.kt")
|
@TestMetadata("topLevel.kt")
|
||||||
public void testTopLevel() throws Exception {
|
public void testTopLevel() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
||||||
|
|||||||
@@ -9365,6 +9365,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonAbstractInInterface.kt")
|
||||||
|
public void testNonAbstractInInterface() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/nonAbstractInInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevel.kt")
|
@TestMetadata("topLevel.kt")
|
||||||
public void testTopLevel() throws Exception {
|
public void testTopLevel() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionProperties/topLevel.kt");
|
||||||
|
|||||||
+22
-19
@@ -23,16 +23,11 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.js.backend.ast.*
|
import org.jetbrains.kotlin.js.backend.ast.*
|
||||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
import org.jetbrains.kotlin.js.translate.utils.*
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.prototypeOf
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.prototypeOf
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.pureFqn
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.pureFqn
|
||||||
import org.jetbrains.kotlin.js.translate.utils.generateDelegateCall
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOrInheritsParametersWithDefaultValue
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOwnParametersWithDefaultValue
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||||
import org.jetbrains.kotlin.utils.identity
|
import org.jetbrains.kotlin.utils.identity
|
||||||
@@ -118,13 +113,7 @@ class ClassModelGenerator(val context: TranslationContext) {
|
|||||||
val classToCopyFrom = memberToCopy.containingDeclaration as ClassDescriptor
|
val classToCopyFrom = memberToCopy.containingDeclaration as ClassDescriptor
|
||||||
if (classToCopyFrom.kind != ClassKind.INTERFACE || AnnotationsUtils.isNativeObject(classToCopyFrom)) return
|
if (classToCopyFrom.kind != ClassKind.INTERFACE || AnnotationsUtils.isNativeObject(classToCopyFrom)) return
|
||||||
|
|
||||||
val name = context.getNameForDescriptor(member).ident
|
copyMember(member, classToCopyFrom, descriptor, model)
|
||||||
when (member) {
|
|
||||||
is FunctionDescriptor -> {
|
|
||||||
copyMethod(name, name, classToCopyFrom, descriptor, model.postDeclarationBlock)
|
|
||||||
}
|
|
||||||
is PropertyDescriptor -> copyProperty(name, classToCopyFrom, descriptor, model.postDeclarationBlock)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyInvisibleFakeMember(descriptor: ClassDescriptor, member: CallableMemberDescriptor, model: JsClassModel) {
|
private fun copyInvisibleFakeMember(descriptor: ClassDescriptor, member: CallableMemberDescriptor, model: JsClassModel) {
|
||||||
@@ -133,12 +122,26 @@ class ClassModelGenerator(val context: TranslationContext) {
|
|||||||
val classToCopyFrom = memberToCopy.containingDeclaration as ClassDescriptor
|
val classToCopyFrom = memberToCopy.containingDeclaration as ClassDescriptor
|
||||||
if (classToCopyFrom.kind != ClassKind.INTERFACE) continue
|
if (classToCopyFrom.kind != ClassKind.INTERFACE) continue
|
||||||
|
|
||||||
val name = context.getNameForDescriptor(memberToCopy).ident
|
copyMember(memberToCopy, classToCopyFrom, descriptor, model)
|
||||||
when (member) {
|
}
|
||||||
is FunctionDescriptor -> {
|
}
|
||||||
copyMethod(name, name, classToCopyFrom, descriptor, model.postDeclarationBlock)
|
|
||||||
|
private fun copyMember(member: CallableMemberDescriptor, from: ClassDescriptor, to: ClassDescriptor, model: JsClassModel) {
|
||||||
|
val name = context.getNameForDescriptor(member).ident
|
||||||
|
when (member) {
|
||||||
|
is FunctionDescriptor -> {
|
||||||
|
copyMethod(name, name, from, to, model.postDeclarationBlock)
|
||||||
|
}
|
||||||
|
is PropertyDescriptor -> {
|
||||||
|
if (TranslationUtils.shouldAccessViaFunctions(member) || member.isExtension) {
|
||||||
|
for (accessor in member.accessors) {
|
||||||
|
val accessorName = context.getNameForDescriptor(accessor).ident
|
||||||
|
copyMethod(accessorName, accessorName, from, to, model.postDeclarationBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
copyProperty(name, from, to, model.postDeclarationBlock)
|
||||||
}
|
}
|
||||||
is PropertyDescriptor -> copyProperty(name, classToCopyFrom, descriptor, model.postDeclarationBlock)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user