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:
+16
-4
@@ -105,15 +105,27 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
require(this is ConeKotlinType)
|
require(this is ConeKotlinType)
|
||||||
// if (this is TypeUtils.SpecialType) return 0 // TODO: WTF?
|
// if (this is TypeUtils.SpecialType) return 0 // TODO: WTF?
|
||||||
|
|
||||||
var result = 0
|
var maxArgumentDepth = 0
|
||||||
for (arg in typeArguments) {
|
for (arg in typeArguments) {
|
||||||
val current = if (arg is ConeStarProjection) 1 else (arg as ConeTypedProjection).type.typeDepth()
|
val current = if (arg is ConeStarProjection) 1 else (arg as ConeTypedProjection).type.typeDepth()
|
||||||
if (current > result) {
|
if (current > maxArgumentDepth) {
|
||||||
result = current
|
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 {
|
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| {
|
||||||
|
}
|
||||||
+5
@@ -928,6 +928,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
public void testSimpleCapturedTypes() throws Exception {
|
public void testSimpleCapturedTypes() throws Exception {
|
||||||
runTest("compiler/fir/resolve/testData/resolve/inference/simpleCapturedTypes.kt");
|
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")
|
@TestMetadata("compiler/fir/resolve/testData/resolve/multifile")
|
||||||
|
|||||||
Generated
+5
@@ -928,6 +928,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
public void testSimpleCapturedTypes() throws Exception {
|
public void testSimpleCapturedTypes() throws Exception {
|
||||||
runTest("compiler/fir/resolve/testData/resolve/inference/simpleCapturedTypes.kt");
|
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")
|
@TestMetadata("compiler/fir/resolve/testData/resolve/multifile")
|
||||||
|
|||||||
Reference in New Issue
Block a user