diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 617fe35f263..5f7d32cd114 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -310,9 +310,9 @@ public interface Errors { // Inline classes - DiagnosticFactory0 INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INLINE_CLASS_NOT_FINAL = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineClassDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineClassDeclarationChecker.kt index c37596a1592..f0d9b0bd52c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineClassDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineClassDeclarationChecker.kt @@ -14,6 +14,8 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtParameter +import org.jetbrains.kotlin.psi.getModificationStamp +import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier import org.jetbrains.kotlin.psi.psiUtil.modalityModifier import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -23,9 +25,12 @@ object InlineClassDeclarationChecker : DeclarationChecker { if (descriptor !is ClassDescriptor || !descriptor.isInline) return if (descriptor.kind != ClassKind.CLASS) return + val inlineKeyword = declaration.modifierList?.getModifier(KtTokens.INLINE_KEYWORD) + require(inlineKeyword != null) { "Declaration of inline class must have 'inline' keyword" } + val trace = context.trace if (!DescriptorUtils.isTopLevelDeclaration(descriptor)) { - trace.report(Errors.INLINE_CLASS_NOT_TOP_LEVEL.on(declaration)) + trace.report(Errors.INLINE_CLASS_NOT_TOP_LEVEL.on(inlineKeyword)) return } @@ -37,7 +42,7 @@ object InlineClassDeclarationChecker : DeclarationChecker { val primaryConstructor = declaration.primaryConstructor if (primaryConstructor == null) { - trace.report(Errors.ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS.on(declaration)) + trace.report(Errors.ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS.on(inlineKeyword)) return } diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.kt index af375ab0807..4af85c4f712 100644 --- a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.kt +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.kt @@ -3,7 +3,7 @@ inline class A0(val x: Int) -inline class A1 +inline class A1 inline class A2() inline class A3(x: Int) inline class A4(var x: Int) @@ -15,14 +15,14 @@ inline class A9(final val x: Int) class B1 { companion object { - inline class C1(val x: Int) + inline class C1(val x: Int) } - inline class C2(val x: Int) + inline class C2(val x: Int) } object B2 { - inline class C3(val x: Int) + inline class C3(val x: Int) } final inline class D0(val x: Int)