diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt index 1fd7d25c6d5..f1b1d5715f7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt @@ -105,15 +105,27 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo require(this is ConeKotlinType) // if (this is TypeUtils.SpecialType) return 0 // TODO: WTF? - var result = 0 + var maxArgumentDepth = 0 for (arg in typeArguments) { val current = if (arg is ConeStarProjection) 1 else (arg as ConeTypedProjection).type.typeDepth() - if (current > result) { - result = current + if (current > maxArgumentDepth) { + maxArgumentDepth = current } } - return result + 1 + var result = maxArgumentDepth + 1 + + if (this is ConeClassLikeType) { + val fullyExpanded = fullyExpandedType(session) + if (this !== fullyExpanded) { + val fullyExpandedTypeDepth = fullyExpanded.typeDepth() + if (fullyExpandedTypeDepth > result) { + result = fullyExpandedTypeDepth + } + } + } + + return result } override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean { diff --git a/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.kt b/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.kt new file mode 100644 index 00000000000..25a10c134ff --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.kt @@ -0,0 +1,14 @@ +typealias SymbolToTransformer = MutableMap Double> + + +fun SymbolToTransformer.add() {} + +fun foo( + symbolToTransformer: SymbolToTransformer +) { + symbolToTransformer.myApply { + add() + } +} + +fun T.myApply(x: T.() -> Unit) {} diff --git a/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.txt b/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.txt new file mode 100644 index 00000000000..78bf46c7d12 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.txt @@ -0,0 +1,12 @@ +FILE: typeDepthForTypeAlias.kt + public final typealias SymbolToTransformer = R|kotlin/collections/MutableMap>| + public final fun R|SymbolToTransformer|.add(): R|kotlin/Unit| { + } + public final fun foo(symbolToTransformer: R|SymbolToTransformer|): R|kotlin/Unit| { + R|/symbolToTransformer|.R|/myApply|>|>( = myApply@fun R|kotlin/collections/MutableMap>|.(): R|kotlin/Unit| { + this@R|special/anonymous|.R|/add|() + } + ) + } + public final fun R|T|.myApply(x: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index bbc8dd8fc55..f2984803b80 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -928,6 +928,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { public void testSimpleCapturedTypes() throws Exception { runTest("compiler/fir/resolve/testData/resolve/inference/simpleCapturedTypes.kt"); } + + @TestMetadata("typeDepthForTypeAlias.kt") + public void testTypeDepthForTypeAlias() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.kt"); + } } @TestMetadata("compiler/fir/resolve/testData/resolve/multifile") diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index fcdf429dc52..57ab2bf54ad 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -928,6 +928,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testSimpleCapturedTypes() throws Exception { runTest("compiler/fir/resolve/testData/resolve/inference/simpleCapturedTypes.kt"); } + + @TestMetadata("typeDepthForTypeAlias.kt") + public void testTypeDepthForTypeAlias() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/inference/typeDepthForTypeAlias.kt"); + } } @TestMetadata("compiler/fir/resolve/testData/resolve/multifile")