提交 293f78ef 编写于 作者: D Denis Zharkov

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
上级 bea37569
class Inv<E>
typealias MyAlias = Inv<out CharSequence>
fun foo(p: MyAlias) {
bar(p).length
}
fun <T : Any> bar(x: Inv<T>): T = TODO()
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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册