JvmDefault. Allow non default inheritance with special flag

#KT-47000
This commit is contained in:
Mikhael Bogdanov
2021-10-30 15:00:15 +02:00
parent c9e7c5d156
commit afc149d460
24 changed files with 461 additions and 6 deletions
@@ -35,6 +35,7 @@ class JvmDefaultChecker(private val jvmTarget: JvmTarget, private val project: P
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
val jvmDefaultMode = context.languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
val allowNonDefaultInheritance = context.languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultAllowNonDefaultInheritance)
val jvmDefaultAnnotation = descriptor.annotations.findAnnotation(JVM_DEFAULT_FQ_NAME)
jvmDefaultAnnotation?.let { annotationDescriptor ->
@@ -62,13 +63,15 @@ class JvmDefaultChecker(private val jvmTarget: JvmTarget, private val project: P
}
}
if (descriptor is ClassDescriptor) {
val hasDeclaredJvmDefaults =
descriptor.unsubstitutedMemberScope.getContributedDescriptors().filterIsInstance<CallableMemberDescriptor>().any {
it.kind.isReal && it.isCompiledToJvmDefault(jvmDefaultMode)
if (!allowNonDefaultInheritance) {
if (descriptor is ClassDescriptor) {
val hasDeclaredJvmDefaults =
descriptor.unsubstitutedMemberScope.getContributedDescriptors().filterIsInstance<CallableMemberDescriptor>().any {
it.kind.isReal && it.isCompiledToJvmDefault(jvmDefaultMode)
}
if (!hasDeclaredJvmDefaults && !checkJvmDefaultsInHierarchy(descriptor, jvmDefaultMode)) {
context.trace.report(ErrorsJvm.JVM_DEFAULT_THROUGH_INHERITANCE.on(declaration))
}
if (!hasDeclaredJvmDefaults && !checkJvmDefaultsInHierarchy(descriptor, jvmDefaultMode)) {
context.trace.report(ErrorsJvm.JVM_DEFAULT_THROUGH_INHERITANCE.on(declaration))
}
}