NI: Add flexible Nothing to trivial constraints to filter it

This commit is contained in:
victor.petukhov
2019-12-11 16:56:12 +03:00
parent 2d5a05466d
commit 71cb65c064
7 changed files with 31 additions and 2 deletions
@@ -10560,6 +10560,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt");
}
@TestMetadata("implicitInferenceTToFlexibleNothing.kt")
public void testImplicitInferenceTToFlexibleNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt");
}
@TestMetadata("implicitNothingConstraintFromReturn.kt")
public void testImplicitNothingConstraintFromReturn() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.kt");
@@ -40,7 +40,7 @@ class TrivialConstraintTypeInferenceOracle(context: TypeSystemInferenceExtension
generatedConstraintType: KotlinTypeMarker,
isSubtype: Boolean
): Boolean {
if (isSubtype && generatedConstraintType.isNothing()) return true
if (isSubtype && (generatedConstraintType.isNothing() || generatedConstraintType.isFlexibleNothing())) return true
if (!isSubtype && generatedConstraintType.isNullableAny()) return true
// If types from constraints that will be used to generate new constraint already contains `Nothing(?)`,
@@ -20,7 +20,7 @@ public class Foo {
// FILE: test.kt
fun test(e: <!UNRESOLVED_REFERENCE!>ErrorType<!>) {
Foo.foo {
Foo.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!> {
Sam.Result.create(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>e<!>)
}
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNCHECKED_CAST -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
// SKIP_TXT
import java.util.*
fun <T> foo (f: () -> List<T>): T = null as T
fun main() {
val x = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!> { Collections.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>() }
}
@@ -10567,6 +10567,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt");
}
@TestMetadata("implicitInferenceTToFlexibleNothing.kt")
public void testImplicitInferenceTToFlexibleNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt");
}
@TestMetadata("implicitNothingConstraintFromReturn.kt")
public void testImplicitNothingConstraintFromReturn() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.kt");
@@ -10562,6 +10562,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt");
}
@TestMetadata("implicitInferenceTToFlexibleNothing.kt")
public void testImplicitInferenceTToFlexibleNothing() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt");
}
@TestMetadata("implicitNothingConstraintFromReturn.kt")
public void testImplicitNothingConstraintFromReturn() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.kt");
@@ -248,6 +248,9 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun KotlinTypeMarker.isNullableAny() = this.typeConstructor().isAnyConstructor() && this.isNullableType()
fun KotlinTypeMarker.isNothing() = this.typeConstructor().isNothingConstructor() && !this.isNullableType()
fun KotlinTypeMarker.isFlexibleNothing() =
this is FlexibleTypeMarker && lowerBound().isNothing() && upperBound().isNullableNothing()
fun KotlinTypeMarker.isNullableNothing() = this.typeConstructor().isNothingConstructor() && this.isNullableType()
fun SimpleTypeMarker.isClassType(): Boolean = typeConstructor().isClassTypeConstructor()