diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.kt new file mode 100644 index 00000000000..4de992d3d8d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER, -CONSTANT_EXPECTED_TYPE_MISMATCH +// This should not crash +package foo + +@JsModule @native fun foo(x: Int): Int + +@JsModule(23) @native fun bar(x: Int): Int \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.txt b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.txt new file mode 100644 index 00000000000..89861369f38 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.txt @@ -0,0 +1,6 @@ +package + +package foo { + @kotlin.js.JsModule(import = 23) @kotlin.js.native public fun bar(/*0*/ x: kotlin.Int): kotlin.Int + @kotlin.js.JsModule @kotlin.js.native public fun foo(/*0*/ x: kotlin.Int): kotlin.Int +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index 0b83f0917dc..54c538bcb76 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -311,6 +311,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } + @TestMetadata("jsModuleWithoutParameters.kt") + public void testJsModuleWithoutParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.kt"); + doTest(fileName); + } + @TestMetadata("jsVarProhibited.kt") public void testJsVarProhibited() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/module/jsVarProhibited.kt"); diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java b/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java index 654002f18bd..76fc4612d61 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java @@ -213,7 +213,10 @@ public final class AnnotationsUtils { DeclarationDescriptor annotationType = annotation.getType().getConstructor().getDeclarationDescriptor(); if (annotationType == null) continue; - FqNameUnsafe fqName = DescriptorUtils.getFqName(annotation.getType().getConstructor().getDeclarationDescriptor()); + DeclarationDescriptor annotationTypeDescriptor = annotation.getType().getConstructor().getDeclarationDescriptor(); + assert annotationTypeDescriptor != null : "Annotation type should have descriptor: " + annotation.getType(); + + FqNameUnsafe fqName = DescriptorUtils.getFqName(annotationTypeDescriptor); if (fqName.equals(JS_NON_MODULE_ANNOTATION.toUnsafe())) { return true; } @@ -222,10 +225,14 @@ public final class AnnotationsUtils { return false; } - @NotNull + @Nullable private static String extractJsModuleName(@NotNull AnnotationDescriptor annotation) { + if (annotation.getAllValueArguments().isEmpty()) return null; + ConstantValue importValue = annotation.getAllValueArguments().values().iterator().next(); - assert importValue != null : "JsModule annotation should have at least one argument"; + if (importValue == null) return null; + + if (!(importValue.getValue() instanceof String)) return null; return (String) importValue.getValue(); }