Prohibit 'native' annotation on constructors

Currently doesn't work for primary ones

 #KT-7000 Fixed
This commit is contained in:
Denis Zharkov
2015-03-20 11:48:13 +03:00
parent 29b03e8175
commit ce3bf423ad
4 changed files with 45 additions and 1 deletions
@@ -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))
}
@@ -0,0 +1,10 @@
class A {
<!INAPPLICABLE_ANNOTATION!>native constructor() {}<!>
inner class B {
<!INAPPLICABLE_ANNOTATION!>native constructor() {}<!>
}
<!INAPPLICABLE_ANNOTATION!>native constructor(<!UNUSED_PARAMETER!>x<!>: Int)
<!>}
class C [native] () // TODO KT-7057
@@ -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
}
@@ -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");