K2: change logic of result type search in ILT case
Related to KT-57487, KT-57703
This commit is contained in:
committed by
Space Team
parent
27c4a7b7ef
commit
08c22c388c
+6
@@ -19230,6 +19230,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexMapping.kt")
|
||||
public void testComplexMapping() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/integerLiterals/complexMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constantUnaryOperators.kt")
|
||||
public void testConstantUnaryOperators() throws Exception {
|
||||
|
||||
+6
@@ -19230,6 +19230,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexMapping.kt")
|
||||
public void testComplexMapping() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/integerLiterals/complexMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constantUnaryOperators.kt")
|
||||
public void testConstantUnaryOperators() throws Exception {
|
||||
|
||||
+6
@@ -19230,6 +19230,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexMapping.kt")
|
||||
public void testComplexMapping() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/integerLiterals/complexMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constantUnaryOperators.kt")
|
||||
public void testConstantUnaryOperators() throws Exception {
|
||||
|
||||
+6
@@ -19236,6 +19236,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexMapping.kt")
|
||||
public void testComplexMapping() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/integerLiterals/complexMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constantUnaryOperators.kt")
|
||||
public void testConstantUnaryOperators() throws Exception {
|
||||
|
||||
+25
-2
@@ -68,17 +68,40 @@ class ResultTypeResolver(
|
||||
variableWithConstraints: VariableWithConstraints,
|
||||
direction: ResolveDirection
|
||||
): KotlinTypeMarker? {
|
||||
findResultIfThereIsEqualsConstraint(c, variableWithConstraints)?.let { return it }
|
||||
val resultTypeFromEqualConstraint = findResultIfThereIsEqualsConstraint(c, variableWithConstraints)
|
||||
if (resultTypeFromEqualConstraint != null) {
|
||||
with(c) {
|
||||
if (!isK2 || !resultTypeFromEqualConstraint.contains { type ->
|
||||
type.typeConstructor().isIntegerLiteralConstantTypeConstructor()
|
||||
}
|
||||
) {
|
||||
// In K2, we don't return here ILT-based types immediately
|
||||
return resultTypeFromEqualConstraint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val subType = c.findSubType(variableWithConstraints)
|
||||
// Super type should be the most flexible, sub type should be the least one
|
||||
val superType = c.findSuperType(variableWithConstraints).makeFlexibleIfNecessary(c, variableWithConstraints.constraints)
|
||||
|
||||
return if (direction == ResolveDirection.TO_SUBTYPE || direction == ResolveDirection.UNKNOWN) {
|
||||
val resultTypeFromDirection = if (direction == ResolveDirection.TO_SUBTYPE || direction == ResolveDirection.UNKNOWN) {
|
||||
c.resultType(subType, superType, variableWithConstraints)
|
||||
} else {
|
||||
c.resultType(superType, subType, variableWithConstraints)
|
||||
}
|
||||
// In the general case, we can have here two types, one from EQUAL constraint which must be ILT-based,
|
||||
// and the second one from UPPER/LOWER constraints (subType/superType based)
|
||||
// The logic of choice here is:
|
||||
// - if one type is null, we return another one
|
||||
// - we return type from UPPER/LOWER constraints if it's more precise
|
||||
// - otherwise we return ILT-based type
|
||||
return when {
|
||||
resultTypeFromEqualConstraint == null -> resultTypeFromDirection
|
||||
resultTypeFromDirection == null -> resultTypeFromEqualConstraint
|
||||
AbstractTypeChecker.isSubtypeOf(c, resultTypeFromDirection, resultTypeFromEqualConstraint) -> resultTypeFromDirection
|
||||
else -> resultTypeFromEqualConstraint
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
-2
@@ -1,8 +1,6 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_K1: JVM_IR
|
||||
// (type mismatch)
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// (CCE in select)
|
||||
// WITH_STDLIB
|
||||
|
||||
fun <A : Comparable<A>> arrayData(vararg values: A): A = values.first()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// WITH_STDLIB
|
||||
// FILE: First.java
|
||||
|
||||
public class First implements Comparable<First> {
|
||||
public static First compose(int something) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Second.java
|
||||
|
||||
public class Second implements Comparable<Second> {
|
||||
public static Second compose(String something) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: complexMapping.kt
|
||||
|
||||
private fun <R : Comparable<R>> range(vararg ranges: Pair<R?, R?>): Ranges<R> = null!!
|
||||
|
||||
private abstract class Ranges<C : Comparable<C>> {
|
||||
abstract fun <M : Comparable<M>> map(transform: (C) -> M): Ranges<M>
|
||||
}
|
||||
|
||||
private val INF: Nothing? = null
|
||||
|
||||
private val foo = listOf(
|
||||
range(0 to 1) to range(INF to ""),
|
||||
range(2 to 3) to range(INF to "", "" to INF),
|
||||
range(4 to 5) to range("" to INF),
|
||||
range(6 to INF) to range("" to INF)
|
||||
).map {
|
||||
it.first.map(First::compose) to it.second.map(Second::compose)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// WITH_STDLIB
|
||||
// FILE: First.java
|
||||
|
||||
public class First implements Comparable<First> {
|
||||
public static First compose(int something) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Second.java
|
||||
|
||||
public class Second implements Comparable<Second> {
|
||||
public static Second compose(String something) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: complexMapping.kt
|
||||
|
||||
private fun <R : Comparable<R>> range(vararg ranges: Pair<R?, R?>): Ranges<R> = null!!
|
||||
|
||||
private abstract class Ranges<C : Comparable<C>> {
|
||||
abstract fun <M : Comparable<M>> map(transform: (C) -> M): Ranges<M>
|
||||
}
|
||||
|
||||
private val INF: Nothing? = null
|
||||
|
||||
private val foo = listOf(
|
||||
range(0 to 1) to range(<!DEBUG_INFO_CONSTANT!>INF<!> to ""),
|
||||
range(2 to 3) to range(<!DEBUG_INFO_CONSTANT!>INF<!> to "", "" to <!DEBUG_INFO_CONSTANT!>INF<!>),
|
||||
range(4 to 5) to range("" to <!DEBUG_INFO_CONSTANT!>INF<!>),
|
||||
range(6 to <!DEBUG_INFO_CONSTANT!>INF<!>) to range("" to <!DEBUG_INFO_CONSTANT!>INF<!>)
|
||||
).map {
|
||||
it.first.map(First::compose) to it.second.map(Second::compose)
|
||||
}
|
||||
@@ -6,9 +6,9 @@ FILE: vararg.fir.kt
|
||||
^arrayDataNoBound Null(null)!!
|
||||
}
|
||||
public final fun test(b: R|kotlin/Byte|): R|kotlin/Unit| {
|
||||
R|/select|<R|kotlin/Byte|>(R|/arrayData|<R|kotlin/Int|>(vararg(Int(1))), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/id|<R|kotlin/Int|>(Int(1)), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/id|<R|kotlin/Int|>(R|/arrayData|<R|kotlin/Int|>(vararg(Int(1)))), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/arrayData|<R|kotlin/Byte|>(vararg(Byte(1))), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/id|<R|kotlin/Byte|>(Byte(1)), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/id|<R|kotlin/Byte|>(R|/arrayData|<R|kotlin/Byte|>(vararg(Byte(1)))), R|<local>/b|)
|
||||
R|/select|<R|kotlin/Byte|>(R|/arrayDataNoBound|<R|kotlin/Byte|>(vararg(Byte(1))), R|<local>/b|)
|
||||
}
|
||||
public final fun <S> select(a: R|S|, b: R|S|): R|S| {
|
||||
|
||||
Generated
+6
@@ -19236,6 +19236,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexMapping.kt")
|
||||
public void testComplexMapping() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/integerLiterals/complexMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constantUnaryOperators.kt")
|
||||
public void testConstantUnaryOperators() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user