Prohibit external modifiers on classes and properties in JVM target
This commit is contained in:
+13
-1
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
@@ -34,7 +36,17 @@ class ExternalFunChecker : SimpleDeclarationChecker {
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
if (descriptor !is FunctionDescriptor || !descriptor.isExternal) return
|
||||
if (descriptor !is MemberDescriptor || !descriptor.isExternal) return
|
||||
|
||||
if (descriptor !is FunctionDescriptor) {
|
||||
val target = when (descriptor) {
|
||||
is PropertyDescriptor -> "property"
|
||||
is ClassDescriptor -> "class"
|
||||
else -> "non-function declaration"
|
||||
}
|
||||
diagnosticHolder.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, target))
|
||||
return
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isInterface(descriptor.containingDeclaration)) {
|
||||
diagnosticHolder.report(ErrorsJvm.EXTERNAL_DECLARATION_IN_INTERFACE.on(declaration))
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<!WRONG_MODIFIER_TARGET!>external class A<!>
|
||||
|
||||
<!WRONG_MODIFIER_TARGET!>external val foo: Int = 23<!>
|
||||
|
||||
class B {
|
||||
<!WRONG_MODIFIER_TARGET!>external class A<!>
|
||||
|
||||
<!WRONG_MODIFIER_TARGET!>external val foo: Int = 23<!>
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public val foo: kotlin.Int = 23
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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
|
||||
}
|
||||
|
||||
public final class B {
|
||||
public constructor B()
|
||||
public final val foo: kotlin.Int = 23
|
||||
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
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -950,6 +950,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonFunction.kt")
|
||||
public void testNonFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("override.kt")
|
||||
public void testOverride() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/native/override.kt");
|
||||
|
||||
Reference in New Issue
Block a user