diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt index c1131506eb8..2574dfd14a9 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt @@ -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)) diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.kt b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.kt new file mode 100644 index 00000000000..d6d31540478 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.kt @@ -0,0 +1,9 @@ +external class A + +external val foo: Int = 23 + +class B { + external class A + + external val foo: Int = 23 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.txt b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.txt new file mode 100644 index 00000000000..498288ab058 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.txt @@ -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 + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 952f83baca8..f39af6c35f1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -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");