[NI] Don't consider Any!-constraint from upper bounds as more specific

#KT-31624 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-05-27 13:18:59 +03:00
parent 8bef345f0f
commit c30e045b1b
6 changed files with 90 additions and 6 deletions
@@ -10219,6 +10219,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
public void testNothingWithCallableReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt");
}
@TestMetadata("platformNothingAsUsefulConstraint.kt")
public void testPlatformNothingAsUsefulConstraint() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveCalls")
@@ -101,12 +101,10 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
return true // T <: T(?!)
}
if (constraintType.isSimpleType()) {
if (constraint.position.from is DeclaredUpperBoundConstraintPosition &&
constraint.kind == UPPER && constraintType.isNullableAny()
) {
return true // T <: Any?
}
if (constraint.position.from is DeclaredUpperBoundConstraintPosition &&
constraint.kind == UPPER && constraintType.isNullableAny()
) {
return true // T <: Any?
}
return false
@@ -0,0 +1,35 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// FILE: Tasks.java
public class Tasks {
public static <T> Inv<T> call(JSam<T> f) {
return null;
}
}
// FILE: JSam.java
public interface JSam<V> {
V call();
}
// FILE: test.kt
fun <K> withLock(g: () -> K): K = g()
class Out<out P>
class Inv<S>
fun <R> Inv<R>.asOut(): Out<R> = TODO()
fun test() {
val o: Out<Int> = Tasks.call {
withLock { TODO() }
}.asOut()
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<(kotlin.Nothing..kotlin.Nothing?)>..Inv<(kotlin.Nothing..kotlin.Nothing?)>?)")!>Tasks.call {
withLock { TODO() }
}<!>
}
@@ -0,0 +1,36 @@
package
public fun test(): kotlin.Unit
public fun </*0*/ K> withLock(/*0*/ g: () -> K): K
public fun </*0*/ R> Inv<R>.asOut(): Out<R>
public final class Inv</*0*/ S> {
public constructor Inv</*0*/ S>()
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 JSam</*0*/ V : kotlin.Any!> {
public abstract fun call(): V!
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 Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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 open class Tasks {
public constructor Tasks()
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
// Static members
public open fun </*0*/ T : kotlin.Any!> call(/*0*/ f: JSam<T!>!): Inv<T!>!
}
@@ -10226,6 +10226,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
public void testNothingWithCallableReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt");
}
@TestMetadata("platformNothingAsUsefulConstraint.kt")
public void testPlatformNothingAsUsefulConstraint() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveCalls")
@@ -10221,6 +10221,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
public void testNothingWithCallableReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt");
}
@TestMetadata("platformNothingAsUsefulConstraint.kt")
public void testPlatformNothingAsUsefulConstraint() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveCalls")