diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAmbiguousAnonymousTypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAmbiguousAnonymousTypeChecker.kt index 60573c70bb9..6ac5797d3ba 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAmbiguousAnonymousTypeChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAmbiguousAnonymousTypeChecker.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration +import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors @@ -45,18 +46,33 @@ object FirAmbiguousAnonymousTypeChecker : FirBasicDeclarationChecker() { else -> error("Should not be there") } ?: return - val classSymbol = typeRef.coneType.toSymbol(context.session) ?: return + checkTypeAndArguments(typeRef.coneType, context, reporter, declaration.source) + } + + private fun checkTypeAndArguments( + type: ConeKotlinType, + context: CheckerContext, + reporter: DiagnosticReporter, + reportOn: KtSourceElement? + ) { + val classSymbol = type.toSymbol(context.session) if (classSymbol is FirAnonymousObjectSymbol && classSymbol.resolvedSuperTypeRefs.size > 1) { // Any anonymous object that has only one super type is already approximated to the super type by // org.jetbrains.kotlin.fir.types.TypeUtilsKt#hideLocalTypeIfNeeded. Hence, any remaining anonymous object must have more than // one super types and hence are ambiguous. reporter.reportOn( - declaration.source, + reportOn, FirErrors.AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, classSymbol.resolvedSuperTypeRefs.map { it.coneType }, context ) } + for (typeArgument in type.typeArguments) { + checkTypeAndArguments( + typeArgument.type ?: continue, + context, reporter, reportOn + ) + } } private val FirBlock.singleExpressionType diff --git a/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt b/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt index e27dc11676c..b3a75c8701f 100644 --- a/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt +++ b/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt @@ -34,11 +34,11 @@ private inline fun foo22(crossinline f: () -> Int) = Inv(Inv(object : I1 { fun bar(): Int = f() } -private inline fun foo31(crossinline f: () -> Int) = Inv(object : I1, I2 { +private inline fun foo31(crossinline f: () -> Int) = Inv(object : I1, I2 { fun bar(): Int = f() }) -private inline fun foo32(crossinline f: () -> Int) = Inv(Inv(object : I1, I2 { +private inline fun foo32(crossinline f: () -> Int) = Inv(Inv(object : I1, I2 { fun bar(): Int = f() }))