[K2] Support reporting of IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS
^KT-59983
This commit is contained in:
committed by
Space Team
parent
bf54fda8ec
commit
6a90926e2e
+1
@@ -126,6 +126,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
|||||||
FirOptInAnnotationClassChecker,
|
FirOptInAnnotationClassChecker,
|
||||||
FirCommonConstructorDelegationIssuesChecker,
|
FirCommonConstructorDelegationIssuesChecker,
|
||||||
FirDelegationSuperCallInEnumConstructorChecker,
|
FirDelegationSuperCallInEnumConstructorChecker,
|
||||||
|
FirDelegationInExpectClassSyntaxChecker,
|
||||||
FirDelegationInInterfaceSyntaxChecker,
|
FirDelegationInInterfaceSyntaxChecker,
|
||||||
FirEnumClassSimpleChecker,
|
FirEnumClassSimpleChecker,
|
||||||
FirLocalEntityNotAllowedChecker,
|
FirLocalEntityNotAllowedChecker,
|
||||||
|
|||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.analysis.checkers.syntax
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.*
|
||||||
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.KtDelegatedSuperTypeEntry
|
||||||
|
|
||||||
|
object FirDelegationInExpectClassSyntaxChecker : FirDeclarationSyntaxChecker<FirRegularClass, KtClassOrObject>() {
|
||||||
|
|
||||||
|
override fun isApplicable(element: FirRegularClass, source: KtSourceElement): Boolean = element.isExpect
|
||||||
|
|
||||||
|
override fun checkPsi(
|
||||||
|
element: FirRegularClass,
|
||||||
|
source: KtPsiSourceElement,
|
||||||
|
psi: KtClassOrObject,
|
||||||
|
context: CheckerContext,
|
||||||
|
reporter: DiagnosticReporter
|
||||||
|
) {
|
||||||
|
for (superTypeRef in element.superTypeRefs) {
|
||||||
|
val superSource = superTypeRef.source ?: continue
|
||||||
|
val parent = superSource.psi?.parent as? KtDelegatedSuperTypeEntry ?: continue
|
||||||
|
reporter.reportOn(KtRealPsiSourceElement(parent), FirErrors.IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun checkLightTree(
|
||||||
|
element: FirRegularClass,
|
||||||
|
source: KtLightSourceElement,
|
||||||
|
context: CheckerContext,
|
||||||
|
reporter: DiagnosticReporter
|
||||||
|
) {
|
||||||
|
for (superTypeRef in element.superTypeRefs) {
|
||||||
|
val superSource = superTypeRef.source ?: continue
|
||||||
|
val parent = superSource.treeStructure.getParent(superSource.lighterASTNode) ?: continue
|
||||||
|
if (parent.tokenType == KtNodeTypes.DELEGATED_SUPER_TYPE_ENTRY) {
|
||||||
|
reporter.reportOn(
|
||||||
|
parent.toKtLightSourceElement(superSource.treeStructure),
|
||||||
|
FirErrors.IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS,
|
||||||
|
context
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -4,6 +4,6 @@
|
|||||||
interface A
|
interface A
|
||||||
|
|
||||||
class B : A
|
class B : A
|
||||||
<!NO_ACTUAL_FOR_EXPECT!>expect class Foo(b: B) : A by b<!>
|
<!NO_ACTUAL_FOR_EXPECT!>expect class Foo(b: B) : <!IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS!>A by b<!><!>
|
||||||
|
|
||||||
<!NO_ACTUAL_FOR_EXPECT!>expect class Bar : A by B()<!>
|
<!NO_ACTUAL_FOR_EXPECT!>expect class Bar : <!IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS!>A by B()<!><!>
|
||||||
|
|||||||
+2
-2
@@ -4,6 +4,6 @@
|
|||||||
interface A
|
interface A
|
||||||
|
|
||||||
class B : A
|
class B : A
|
||||||
expect class Foo(b: B) : A by b
|
expect class Foo(b: B) : <!IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS!>A by b<!>
|
||||||
|
|
||||||
expect class Bar : A by B()
|
expect class Bar : <!IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS!>A by B()<!>
|
||||||
|
|||||||
Reference in New Issue
Block a user