[NI] Prefer between two complex variables one with proper lower bounds

This reverts commit d4d35bb766.
This commit is contained in:
Mikhail Zarechenskiy
2020-03-24 01:56:10 +03:00
parent a4c7619c89
commit ec4d9d2f1f
12 changed files with 135 additions and 3 deletions
@@ -10986,6 +10986,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt");
}
@TestMetadata("inferenceWithRecursiveGenericsAndNothing.kt")
public void testInferenceWithRecursiveGenericsAndNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferenceWithRecursiveGenericsAndNothing.kt");
}
@TestMetadata("kt24490.kt")
public void testKt24490() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/kt24490.kt");
@@ -2384,6 +2384,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.kt");
}
@TestMetadata("kt37554.kt")
public void testKt37554() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt37554.kt");
}
@TestMetadata("kt9820_javaFunctionTypeInheritor.kt")
public void testKt9820_javaFunctionTypeInheritor() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.kt");
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.PARTIAL
import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker
@@ -53,7 +54,8 @@ class VariableFixationFinder(
enum class TypeVariableFixationReadiness {
FORBIDDEN,
WITHOUT_PROPER_ARGUMENT_CONSTRAINT, // proper constraint from arguments -- not from upper bound for type parameters
WITH_COMPLEX_DEPENDENCY, // if type variable T has constraint with non fixed type variable inside (non-top-level): T <: Foo<S>
WITH_COMPLEX_DEPENDENCY_LOWER, // if type variable T has constraint with non fixed type variable inside (non-top-level): T <: Foo<S>
WITH_COMPLEX_DEPENDENCY_UPPER, // Foo<S> <: T
WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS, // proper trivial constraint from arguments, Nothing <: T
RELATED_TO_ANY_OUTPUT_TYPE,
READY_FOR_FIXATION,
@@ -67,7 +69,8 @@ class VariableFixationFinder(
!notFixedTypeVariables.contains(variable) ||
dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN
!variableHasProperArgumentConstraints(variable) -> TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT
hasDependencyToOtherTypeVariables(variable) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY
hasDependencyToOtherTypeVariables(variable, ConstraintKind.LOWER) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY_LOWER
hasDependencyToOtherTypeVariables(variable, ConstraintKind.UPPER) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY_UPPER
variableHasTrivialOrNonProperConstraints(variable) -> TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS
dependencyProvider.isVariableRelatedToAnyOutputType(variable) -> TypeVariableFixationReadiness.RELATED_TO_ANY_OUTPUT_TYPE
isReified(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_REIFIED
@@ -118,8 +121,9 @@ class VariableFixationFinder(
}
}
private fun Context.hasDependencyToOtherTypeVariables(typeVariable: TypeConstructorMarker): Boolean {
private fun Context.hasDependencyToOtherTypeVariables(typeVariable: TypeConstructorMarker, kind: ConstraintKind): Boolean {
for (constraint in notFixedTypeVariables[typeVariable]?.constraints ?: return false) {
if (constraint.kind != kind || constraint.kind == ConstraintKind.EQUALITY) continue
if (constraint.type.lowerBoundIfFlexible().argumentsCount() != 0 && constraint.type.contains { notFixedTypeVariables.containsKey(it.typeConstructor()) }) {
return true
}
@@ -0,0 +1,16 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Out<out T>
interface In<in T>
interface Recursive<T : In<T>>
interface Specialized : In<Specialized>
class Parent : Specialized
fun <T : In<T>> foo(o: Out<T>): Recursive<T>? = null
fun test(o: Out<Parent>) {
foo(o) ?: return
}
@@ -0,0 +1,35 @@
package
public fun </*0*/ T : In<T>> foo(/*0*/ o: Out<T>): Recursive<T>?
public fun test(/*0*/ o: Out<Parent>): kotlin.Unit
public interface In</*0*/ in T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Out</*0*/ out T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Parent : Specialized {
public constructor Parent()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Recursive</*0*/ T : In<T>> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Specialized : In<Specialized> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,20 @@
// FIR_IDENTICAL
// FULL_JDK
import java.time.LocalDate
data class DailyTime(val date: LocalDate)
fun <T : Comparable<T>> Sequence<T>.range(): ClosedRange<T>? {
val iter = iterator()
return when {
iter.hasNext() -> iter.next().let { it..it }
else -> null
}
}
fun test(dailyTimes: List<DailyTime>): List<DailyTime> {
val dateRange = dailyTimes.asSequence().map { it.date }.range() ?: return emptyList()
println(dateRange.start)
return dailyTimes
}
@@ -0,0 +1,14 @@
package
public fun test(/*0*/ dailyTimes: kotlin.collections.List<DailyTime>): kotlin.collections.List<DailyTime>
public fun </*0*/ T : kotlin.Comparable<T>> kotlin.sequences.Sequence<T>.range(): kotlin.ranges.ClosedRange<T>?
public final data class DailyTime {
public constructor DailyTime(/*0*/ date: java.time.LocalDate)
public final val date: java.time.LocalDate
public final operator /*synthesized*/ fun component1(): java.time.LocalDate
public final /*synthesized*/ fun copy(/*0*/ date: java.time.LocalDate = ...): DailyTime
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
@@ -10993,6 +10993,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt");
}
@TestMetadata("inferenceWithRecursiveGenericsAndNothing.kt")
public void testInferenceWithRecursiveGenericsAndNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferenceWithRecursiveGenericsAndNothing.kt");
}
@TestMetadata("kt24490.kt")
public void testKt24490() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/kt24490.kt");
@@ -3364,6 +3364,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.kt");
}
@TestMetadata("kt37554.kt")
public void testKt37554() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt37554.kt");
}
@TestMetadata("kt9820_javaFunctionTypeInheritor.kt")
public void testKt9820_javaFunctionTypeInheritor() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.kt");
@@ -3364,6 +3364,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.kt");
}
@TestMetadata("kt37554.kt")
public void testKt37554() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt37554.kt");
}
@TestMetadata("kt9820_javaFunctionTypeInheritor.kt")
public void testKt9820_javaFunctionTypeInheritor() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.kt");
@@ -10988,6 +10988,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt");
}
@TestMetadata("inferenceWithRecursiveGenericsAndNothing.kt")
public void testInferenceWithRecursiveGenericsAndNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferenceWithRecursiveGenericsAndNothing.kt");
}
@TestMetadata("kt24490.kt")
public void testKt24490() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/kt24490.kt");
@@ -53,6 +53,19 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
runTest("idea/testData/decompiler/decompiledTextJvm/TypeAliases/");
}
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/EnumWithQuotes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class EnumWithQuotes extends AbstractJvmDecompiledTextTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInEnumWithQuotes() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/decompiler/decompiledTextJvm/EnumWithQuotes"), Pattern.compile("^([^\\.]+)$"), null, true);
}
}
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/Modifiers")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)