[FE] Fix checker of DEFAULT_ARGUMENTS_IN_EXPECT_WITH_ACTUAL_TYPEALIAS

...not reporting on companion object members as well as other
nested classes.

Annotation classes are accepted because this is how it already worked,
see other tests, for example `annotationsViaActualTypeAlias.kt`.

Test for nested annotation classes will be added in subsequent commit,
because it currently will fail in test
`TreeCompareTest.testCompareDiagnostics` because light-tree2fir
produces different tree due to a bug when converting properties
from expect primary constructor. See subsequent commit for a fix.

Review: KT-MR-12107

^KT-61784
This commit is contained in:
Roman Efremov
2023-09-08 12:23:45 +02:00
committed by Space Team
parent e0e2a57e3d
commit c6d7f15070
7 changed files with 128 additions and 20 deletions
@@ -244,18 +244,9 @@ class ExpectedActualDeclarationChecker(
context: DeclarationCheckerContext,
) {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) return
if (expectDescriptor !is ClassDescriptor ||
actualDeclaration !is KtTypeAlias ||
expectDescriptor.kind == ClassKind.ANNOTATION_CLASS
) return
val members = expectDescriptor.constructors + expectDescriptor.unsubstitutedMemberScope
.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
.filterIsInstance<FunctionDescriptor>()
val membersWithDefaultValueParameters = members
.filter { it.valueParameters.any { p -> p.declaresDefaultValue() }}
if (expectDescriptor !is ClassDescriptor || actualDeclaration !is KtTypeAlias) return
val membersWithDefaultValueParameters = getMembersWithDefaultValueParametersUnlessAnnotation(expectDescriptor)
if (membersWithDefaultValueParameters.isEmpty()) return
context.trace.report(
@@ -267,6 +258,32 @@ class ExpectedActualDeclarationChecker(
)
}
private fun getMembersWithDefaultValueParametersUnlessAnnotation(classDescriptor: ClassDescriptor): List<FunctionDescriptor> {
val result = mutableListOf<FunctionDescriptor>()
fun collectFunctions(classDescriptor: ClassDescriptor) {
if (classDescriptor.kind == ClassKind.ANNOTATION_CLASS) {
return
}
val functionsAndConstructors = classDescriptor.constructors + classDescriptor.unsubstitutedMemberScope
.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
.filterIsInstance<FunctionDescriptor>()
functionsAndConstructors.filterTo(result) { it.valueParameters.any { p -> p.declaresDefaultValue() } }
val nestedClasses = classDescriptor.unsubstitutedMemberScope
.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS)
.filterIsInstance<ClassDescriptor>()
for (nestedClass in nestedClasses) {
collectFunctions(nestedClass)
}
}
collectFunctions(classDescriptor)
return result
}
private fun MemberDescriptor.hasNoActualWithDiagnostic(
compatibility: Map<ExpectActualCompatibility<MemberDescriptor>, List<MemberDescriptor>>
): Boolean {