FIR: Fix hanging inference case with intersection types

This commit is contained in:
Denis Zharkov
2020-04-07 14:18:55 +03:00
parent 81d9cf76f2
commit 65e90743df
5 changed files with 69 additions and 0 deletions
@@ -0,0 +1,16 @@
// FILE: MyList.java
public interface MyList<E> extends java.util.List<E>, I {}
// FILE: main.kt
fun <R> elemAndList(r: R, t: MutableList<R>): R = TODO()
interface I
class A : Comparable<A>, I
class B : Comparable<B>, I
fun test() {
elemAndList(A(), list(B()))
}
fun <T> list(value: T): MyList<T> = TODO()
@@ -0,0 +1,24 @@
FILE: main.kt
public final fun <R> elemAndList(r: R|R|, t: R|kotlin/collections/MutableList<R>|): R|R| {
^elemAndList R|kotlin/TODO|()
}
public abstract interface I : R|kotlin/Any| {
}
public final class A : R|kotlin/Comparable<A>|, R|I| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final class B : R|kotlin/Comparable<B>|, R|I| {
public constructor(): R|B| {
super<R|kotlin/Any|>()
}
}
public final fun test(): R|kotlin/Unit| {
R|/elemAndList|<R|ft<it(kotlin/Comparable<it(A & B)> & I), it(kotlin/Comparable<it(A & B)>? & I?)>|>(R|/A.A|(), R|/list|<R|ft<it(kotlin/Comparable<it(A & B)> & I), it(kotlin/Comparable<it(A & B)>? & I?)>|>(R|/B.B|()))
}
public final fun <T> list(value: R|T|): R|MyList<T>| {
^list R|kotlin/TODO|()
}
@@ -1351,6 +1351,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/extensionCallableReferences.kt");
}
@TestMetadata("intersectionTypesInConstraints.kt")
public void testIntersectionTypesInConstraints() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/intersectionTypesInConstraints.kt");
}
@TestMetadata("lambdaAsReturnStatementOfLambda.kt")
public void testLambdaAsReturnStatementOfLambda() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt");
@@ -1351,6 +1351,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/inference/extensionCallableReferences.kt");
}
@TestMetadata("intersectionTypesInConstraints.kt")
public void testIntersectionTypesInConstraints() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/intersectionTypesInConstraints.kt");
}
@TestMetadata("lambdaAsReturnStatementOfLambda.kt")
public void testLambdaAsReturnStatementOfLambda() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt");
@@ -195,6 +195,25 @@ class ConeIntersectionType(
override val nullability: ConeNullability
get() = ConeNullability.NOT_NULL
private var hashCode = 0
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeIntersectionType
if (intersectedTypes != other.intersectedTypes) return false
return true
}
override fun hashCode(): Int {
if (hashCode != 0) return hashCode
return intersectedTypes.hashCode().also { hashCode = it }
}
}
fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): ConeIntersectionType {