Report error on native members of traits
This commit is contained in:
+1
@@ -49,6 +49,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
MAP.put(ErrorsJvm.PLATFORM_STATIC_ILLEGAL_USAGE, "This declaration does not support ''platformStatic''", DescriptorRenderer.SHORT_NAMES_IN_TYPES);
|
||||
MAP.put(ErrorsJvm.NATIVE_DECLARATION_CANNOT_BE_ABSTRACT, "Native declaration can not be abstract");
|
||||
MAP.put(ErrorsJvm.NATIVE_DECLARATION_CANNOT_HAVE_BODY, "Native declaration can not have a body");
|
||||
MAP.put(ErrorsJvm.NATIVE_DECLARATION_IN_TRAIT, "Members of traits can not be native");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public interface ErrorsJvm {
|
||||
|
||||
DiagnosticFactory0<JetDeclaration> NATIVE_DECLARATION_CANNOT_BE_ABSTRACT = DiagnosticFactory0.create(ERROR, ABSTRACT_MODIFIER);
|
||||
DiagnosticFactory0<JetDeclaration> NATIVE_DECLARATION_CANNOT_HAVE_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<JetDeclaration> NATIVE_DECLARATION_IN_TRAIT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
@@ -54,7 +54,11 @@ class SuppressNoBodyErrorsForNativeDeclarations : DiagnosticsWithSuppression.Sup
|
||||
public class NativeFunChecker : AnnotationChecker {
|
||||
override fun check(declaration: JetDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
if (!descriptor.hasNativeAnnotation()) return
|
||||
if (descriptor is CallableMemberDescriptor &&
|
||||
|
||||
if (DescriptorUtils.isTrait(descriptor.getContainingDeclaration())) {
|
||||
diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_IN_TRAIT.on(declaration))
|
||||
}
|
||||
else if (descriptor is CallableMemberDescriptor &&
|
||||
descriptor.getModality() == Modality.ABSTRACT) {
|
||||
diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_BE_ABSTRACT.on(declaration))
|
||||
}
|
||||
@@ -62,5 +66,6 @@ public class NativeFunChecker : AnnotationChecker {
|
||||
if (declaration is JetDeclarationWithBody && declaration.hasBody()) {
|
||||
diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_HAVE_BODY.on(declaration))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.jvm.*
|
||||
|
||||
trait Tr {
|
||||
<!NATIVE_DECLARATION_IN_TRAIT!>native fun foo()<!>
|
||||
<!NATIVE_DECLARATION_IN_TRAIT, NATIVE_DECLARATION_CANNOT_HAVE_BODY!>native fun bar()<!> {}
|
||||
|
||||
class object {
|
||||
native fun foo()
|
||||
<!NATIVE_DECLARATION_CANNOT_HAVE_BODY!>native fun bar()<!> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
internal trait Tr {
|
||||
kotlin.jvm.native() internal open fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
kotlin.jvm.native() internal abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal class object <class-object-for-Tr> {
|
||||
private constructor <class-object-for-Tr>()
|
||||
kotlin.jvm.native() internal final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
kotlin.jvm.native() internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -673,6 +673,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/noBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("trait.kt")
|
||||
public void testTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/trait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/reified")
|
||||
|
||||
Reference in New Issue
Block a user