FIR: Fix inference when bound comes from type alias

It's type depth may be computed incorrectly
and relevant constraint is being skipped
This commit is contained in:
Denis Zharkov
2020-02-07 16:26:38 +03:00
parent 733e596eed
commit b3f9fa22b4
5 changed files with 52 additions and 4 deletions
@@ -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 {
@@ -0,0 +1,14 @@
typealias SymbolToTransformer = MutableMap<Int, (String) -> Double>
fun SymbolToTransformer.add() {}
fun foo(
symbolToTransformer: SymbolToTransformer
) {
symbolToTransformer.myApply {
add()
}
}
fun <T> T.myApply(x: T.() -> Unit) {}
@@ -0,0 +1,12 @@
FILE: typeDepthForTypeAlias.kt
public final typealias SymbolToTransformer = R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|
public final fun R|SymbolToTransformer|.add(): R|kotlin/Unit| {
}
public final fun foo(symbolToTransformer: R|SymbolToTransformer|): R|kotlin/Unit| {
R|<local>/symbolToTransformer|.R|/myApply|<R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|>(<L> = myApply@fun R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|.<anonymous>(): R|kotlin/Unit| {
this@R|special/anonymous|.R|/add|()
}
)
}
public final fun <T> R|T|.myApply(x: R|T.() -> kotlin/Unit|): R|kotlin/Unit| {
}
@@ -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")
@@ -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")