Don't report diagnostics on the whole declaration, use main keyword

This commit is contained in:
Mikhail Zarechenskiy
2018-05-06 03:10:10 +03:00
parent ed4fd2bb2f
commit 096fe1c411
3 changed files with 13 additions and 8 deletions
@@ -310,9 +310,9 @@ public interface Errors {
// Inline classes
DiagnosticFactory0<KtClass> INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_FINAL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtClass> ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtElement> INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtParameter> INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER = DiagnosticFactory0.create(ERROR);
@@ -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
}
@@ -3,7 +3,7 @@
inline class A0(val x: Int)
<!ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS!>inline class A1<!>
<!ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS!>inline<!> class A1
inline class A2<!INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE!>()<!>
inline class A3(<!INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER!>x: Int<!>)
inline class A4(<!INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER!>var x: Int<!>)
@@ -15,14 +15,14 @@ inline class A9(final val x: Int)
class B1 {
companion object {
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline class C1(val x: Int)<!>
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline<!> class C1(val x: Int)
}
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline class C2(val x: Int)<!>
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline<!> class C2(val x: Int)
}
object B2 {
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline class C3(val x: Int)<!>
<!INLINE_CLASS_NOT_TOP_LEVEL!>inline<!> class C3(val x: Int)
}
final inline class D0(val x: Int)