From 51e5b5aac7217a6e96255401b1183ab45a165d98 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 28 Dec 2016 15:43:10 +0300 Subject: [PATCH] JS: allow to inherit external class from kotlin.Throwable. See KT-15336 --- .../js/resolve/diagnostics/JsExternalChecker.kt | 7 ++----- .../kotlin/js/test/semantics/BoxJsTestGenerated.java | 6 ++++++ js/js.translator/testData/box/native/exception.kt | 11 +++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 js/js.translator/testData/box/native/exception.kt diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt index 602fe430501..2717742b7fc 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt @@ -28,10 +28,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny -import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces -import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension +import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.utils.singletonOrEmptyList @@ -78,7 +75,7 @@ object JsExternalChecker : SimpleDeclarationChecker { if (descriptor.kind == ClassKind.ENUM_CLASS || descriptor.kind == ClassKind.ENUM_ENTRY) { superClasses.removeAll { it.fqNameUnsafe == KotlinBuiltIns.FQ_NAMES._enum } } - if (superClasses.any { !AnnotationsUtils.isNativeObject(it) }) { + if (superClasses.any { !AnnotationsUtils.isNativeObject(it) && it.fqNameSafe != KotlinBuiltIns.FQ_NAMES.throwable }) { diagnosticHolder.report(ErrorsJs.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE.on(declaration)) } } 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 835e20bb9bd..412bb5bf482 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 @@ -5807,6 +5807,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } + @TestMetadata("exception.kt") + public void testException() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/exception.kt"); + doTest(fileName); + } + @TestMetadata("inheritanceFromNativeClass.kt") public void testInheritanceFromNativeClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/inheritanceFromNativeClass.kt"); diff --git a/js/js.translator/testData/box/native/exception.kt b/js/js.translator/testData/box/native/exception.kt new file mode 100644 index 00000000000..c315527f5b3 --- /dev/null +++ b/js/js.translator/testData/box/native/exception.kt @@ -0,0 +1,11 @@ +external class TypeError(message: String?, fileName: String? = definedExternally, lineNumber: Int? = definedExternally) : Throwable + +fun box(): String { + try { + js("null.foo()") + return "fail: expected exception not thrown" + } + catch (e: TypeError) { + return "OK" + } +} \ No newline at end of file