FIR: Correct capturing for type-alias bases arguments

NB: The test data change at testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt
is correct: see the relevant non-fir test, the call shouldn't be applicable

^KT-39008 Fixed
This commit is contained in:
Denis Zharkov
2020-06-10 13:20:25 +03:00
parent bea37569e6
commit 293f78efe8
6 changed files with 41 additions and 2 deletions
@@ -0,0 +1,9 @@
class Inv<E>
typealias MyAlias = Inv<out CharSequence>
fun foo(p: MyAlias) {
bar(p).length
}
fun <T : Any> bar(x: Inv<T>): T = TODO()
@@ -0,0 +1,14 @@
FILE: typeAliasWithNotNullBound.kt
public final class Inv<E> : R|kotlin/Any| {
public constructor<E>(): R|Inv<E>| {
super<R|kotlin/Any|>()
}
}
public final typealias MyAlias = R|Inv<out kotlin/CharSequence>|
public final fun foo(p: R|MyAlias|): R|kotlin/Unit| {
R|/bar|<R|CapturedType(out kotlin/CharSequence)|>(R|<local>/p|).R|kotlin/CharSequence.length|
}
public final fun <T : R|kotlin/Any|> bar(x: R|Inv<T>|): R|T| {
^bar R|kotlin/TODO|()
}
@@ -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")
@@ -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")
@@ -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
@@ -14,4 +14,4 @@ typealias TMap<T> = Map<T, T>
fun <T> foo2(m: TMap<T>) = m
fun bar2(m: TMap<*>) =
foo2(m)
<!INAPPLICABLE_CANDIDATE!>foo2<!>(m)