KT-12877: don't throw exception when @JsModule annotation is improperly used
This commit is contained in:
committed by
Alexey Andreev
parent
d40e923722
commit
df88ebb1b3
+7
@@ -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
|
||||
+6
@@ -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
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user