From e1248f8f0bb003c15164b6d87e20a0e1fce49dd4 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Wed, 16 Nov 2016 23:27:09 +0300 Subject: [PATCH] KJS: don't copy members from native interfaces --- .../js/test/semantics/BoxJsTestGenerated.java | 6 ++++++ .../declaration/InterfaceFunctionCopier.kt | 6 +++++- .../box/inheritance/fromNativeInterface.kt | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/box/inheritance/fromNativeInterface.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 06e3124146f..945bddabab8 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -3437,6 +3437,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } + @TestMetadata("fromNativeInterface.kt") + public void testFromNativeInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inheritance/fromNativeInterface.kt"); + doTest(fileName); + } + @TestMetadata("inheritFromCharIterator.kt") public void testInheritFromCharIterator() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inheritance/inheritFromCharIterator.kt"); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/InterfaceFunctionCopier.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/InterfaceFunctionCopier.kt index 781d11aaf32..7bf411dfd26 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/InterfaceFunctionCopier.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/InterfaceFunctionCopier.kt @@ -22,6 +22,7 @@ import com.google.dart.compiler.backend.js.ast.JsNameRef import org.jetbrains.kotlin.backend.common.bridges.generateBridgesForFunctionDescriptor import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.js.translate.context.StaticContext +import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject 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.pureFqn @@ -43,6 +44,9 @@ class InterfaceFunctionCopier(val context: StaticContext) { } private fun addInterfaceDefaultMembers(descriptor: ClassDescriptor, context: StaticContext) { + // optimization: don't do anything for native declarations + if (isNativeObject(descriptor)) return + val classModel = ClassModel(descriptor) classModels[descriptor] = classModel @@ -60,7 +64,7 @@ class InterfaceFunctionCopier(val context: StaticContext) { } val superModels = DescriptorUtils.getSuperclassDescriptors(descriptor) - .filter { it.kind == ClassKind.INTERFACE } + .filter { it.kind == ClassKind.INTERFACE && !isNativeObject(it) } .map { classModels[it]!! } for (superModel in superModels) { for (name in superModel.copiedFunctions) { diff --git a/js/js.translator/testData/box/inheritance/fromNativeInterface.kt b/js/js.translator/testData/box/inheritance/fromNativeInterface.kt new file mode 100644 index 00000000000..09bf7a7a7d2 --- /dev/null +++ b/js/js.translator/testData/box/inheritance/fromNativeInterface.kt @@ -0,0 +1,15 @@ +package foo + +@native +interface A { + val bar: Int get() = noImpl + fun foo(): String = noImpl +} + +class C : A + +fun box(): String { + val c = C() + + return "OK" +}