Skip to content

Commit

Permalink
Self types: diagnostics for annotation classes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim092001 committed Jan 14, 2023
1 parent 9cdec30 commit ec1ca0f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FILE: selfTypeForAnnotation.kt
@R|kotlin/Self|() public final annotation class AnnotationClass<out <Self> : R|AnnotationClass<<Self>>|> : R|kotlin/Annotation| {
public constructor<out <Self> : R|AnnotationClass<<Self>>|>(): R|AnnotationClass<<Self>>| {
super<R|kotlin/Any|>()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
import kotlin.Self
<!SELF_TYPE_INAPPLICABLE_TARGET!>@Self<!>
annotation class AnnotationClass {

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor
import org.jetbrains.kotlin.fir.declarations.utils.hasBackingField
import org.jetbrains.kotlin.fir.declarations.utils.isAnnotationClass
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.packageFqName
Expand Down Expand Up @@ -71,8 +72,16 @@ object FirAnnotationChecker : FirBasicDeclarationChecker() {
}
}

if (declaration is FirClass && declaration.isEnumClass && self != null) {
reporter.reportOn(self.source, FirErrors.SELF_TYPE_INAPPLICABLE_TARGET, "", context)
if (self != null) {
if (declaration is FirClass) {
if (declaration.isEnumClass) {
reporter.reportOn(self.source, FirErrors.SELF_TYPE_INAPPLICABLE_TARGET, "", context)
}

if (declaration.isAnnotationClass) {
reporter.reportOn(self.source, FirErrors.SELF_TYPE_INAPPLICABLE_TARGET, "", context)
}
}
}

if (deprecatedSinceKotlin != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ inline val FirClass.isInterface: Boolean
inline val FirClass.isEnumClass: Boolean
get() = classKind.isEnumClass

inline val FirClass.isAnnotationClass: Boolean
get() = classKind.isAnnotationClass

inline val FirRegularClass.isSealed: Boolean get() = status.modality == Modality.SEALED

inline val FirRegularClass.canHaveAbstractDeclaration: Boolean
Expand Down

0 comments on commit ec1ca0f

Please sign in to comment.