diff --git a/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt new file mode 100644 index 00000000000..b14854e0a72 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt @@ -0,0 +1,9 @@ +class Inv + +typealias MyAlias = Inv + +fun foo(p: MyAlias) { + bar(p).length +} + +fun bar(x: Inv): T = TODO() diff --git a/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.txt b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.txt new file mode 100644 index 00000000000..3fe6693c865 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.txt @@ -0,0 +1,14 @@ +FILE: typeAliasWithNotNullBound.kt + public final class Inv : R|kotlin/Any| { + public constructor(): R|Inv| { + super() + } + + } + public final typealias MyAlias = R|Inv| + public final fun foo(p: R|MyAlias|): R|kotlin/Unit| { + R|/bar|(R|/p|).R|kotlin/CharSequence.length| + } + public final fun bar(x: R|Inv|): R|T| { + ^bar R|kotlin/TODO|() + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 1f1f945b602..35d6a0b8503 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -633,6 +633,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { public void testSafeCallOnTypeAlias() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/safeCallOnTypeAlias.kt"); } + + @TestMetadata("typeAliasWithNotNullBound.kt") + public void testTypeAliasWithNotNullBound() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/cfg") diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 9bd8a7f530a..090ad7a94ed 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -633,6 +633,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testSafeCallOnTypeAlias() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/safeCallOnTypeAlias.kt"); } + + @TestMetadata("typeAliasWithNotNullBound.kt") + public void testTypeAliasWithNotNullBound() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/cfg") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index d2cd4bbb5d6..387eb14b1a9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -241,7 +241,13 @@ private fun Candidate.captureTypeFromExpressionOrNull(argumentType: ConeKotlinTy return captureTypeFromExpressionOrNull(argumentType.lowerBound) } - if (argumentType.typeArguments.isEmpty() || argumentType !is ConeClassLikeType) return null + if (argumentType !is ConeClassLikeType) return null + + argumentType.fullyExpandedType(bodyResolveComponents.session).let { + if (it !== argumentType) return captureTypeFromExpressionOrNull(it) + } + + if (argumentType.typeArguments.isEmpty()) return null return bodyResolveComponents.inferenceComponents.ctx.captureFromArguments( argumentType, CaptureStatus.FROM_EXPRESSION diff --git a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt index 6e62fc11653..c18d9f69a1e 100644 --- a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt @@ -14,4 +14,4 @@ typealias TMap = Map fun foo2(m: TMap) = m fun bar2(m: TMap<*>) = - foo2(m) + foo2(m)