From ce3bf423ade9425dfcbc0925102db033a0dfaa7d Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 20 Mar 2015 11:48:13 +0300 Subject: [PATCH] Prohibit 'native' annotation on constructors Currently doesn't work for primary ones #KT-7000 Fixed --- .../jetbrains/kotlin/load/kotlin/native.kt | 7 +++++- .../testsWithStdLib/native/constructor.kt | 10 ++++++++ .../testsWithStdLib/native/constructor.txt | 23 +++++++++++++++++++ ...JetDiagnosticsTestWithStdLibGenerated.java | 6 +++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/constructor.txt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt index 3ebb542c48d..38b2d42bd8a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt @@ -23,7 +23,9 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.psi.JetDeclarationWithBody import org.jetbrains.kotlin.resolve.annotations.hasInlineAnnotation @@ -50,7 +52,10 @@ public class NativeFunChecker : DeclarationChecker { diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_BE_ABSTRACT.on(declaration)) } - if (declaration is JetDeclarationWithBody && declaration.hasBody()) { + if (descriptor is ConstructorDescriptor) { + diagnosticHolder.report(Errors.INAPPLICABLE_ANNOTATION.on(declaration)); + } + else if (declaration is JetDeclarationWithBody && declaration.hasBody()) { diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_HAVE_BODY.on(declaration)) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt new file mode 100644 index 00000000000..6a4c0314ad3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt @@ -0,0 +1,10 @@ +class A { + native constructor() {} + inner class B { + native constructor() {} + } + + native constructor(x: Int) +} + +class C [native] () // TODO KT-7057 diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.txt b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.txt new file mode 100644 index 00000000000..645634c0081 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.txt @@ -0,0 +1,23 @@ +package + +internal final class A { + kotlin.jvm.native() public constructor A() + kotlin.jvm.native() public constructor A(/*0*/ x: kotlin.Int) + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal final inner class B { + kotlin.jvm.native() public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +internal final class C { + kotlin.jvm.native() public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java index 650dfe86fc1..fe423d3da32 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java @@ -754,6 +754,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic doTest(fileName); } + @TestMetadata("constructor.kt") + public void testConstructor() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt"); + doTest(fileName); + } + @TestMetadata("inline.kt") public void testInline() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/inline.kt");