From 3eda7c462bce92a73f36911ff38f294e052fbf4d Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 25 Mar 2019 11:09:40 +0300 Subject: [PATCH] [NI] Add `Nothing` constraint if it was inferred from a call --- .../calls/inference/components/ConstraintInjector.kt | 1 - .../constraints/ignoreConstraintFromImplicitInNothing.kt | 4 ++-- .../implicitInvokeExtensionWithFunctionalArgument.kt | 2 +- ...plicitInvokeInCompanionObjectWithFunctionalArgument.kt | 2 +- .../implicitInvokeInObjectWithFunctionalArgument.kt | 2 +- .../implicitInvokeWithFunctionLiteralArgument.kt | 2 +- .../properties/inferenceFromGetters/nullAsNothing.kt | 2 +- .../reportTypeMismatchDeeplyOnBranches.kt | 6 +++--- .../typeParameters/implicitNothingAsTypeParameter.kt | 8 ++++---- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index ae1205baf80..950f4b059d9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -106,7 +106,6 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val if (constraintType is SimpleType) { if (constraint.kind == UPPER && constraintType.isNullableAny()) return true // T <: Any? - if (constraint.kind == LOWER && constraintType.isNothing()) return true // T >: Nothing } return false diff --git a/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt b/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt index 1fa3586927a..31bede9221c 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt @@ -9,8 +9,8 @@ inline fun foo2(f: (T) -> Unit): Foo = Foo() fun test1() { val f1: Foo = foo1 { it checkType { _() } } - val f2: Foo = foo1 { it checkType { _() } } + val f2: Foo = foo1 { it checkType { _() } } val f3: Foo = foo2 { it checkType { _() } } - val f4: Foo = foo2 { it checkType { _() } } + val f4: Foo = foo2 { it checkType { _() } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt index c4342b81eaf..2b134d0d5d5 100644 --- a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt @@ -23,7 +23,7 @@ fun test(s: SelectorFor): Double { d checkType { _>() } val e = s { return p1 } - e checkType { _>() } + e checkType { _>() } return null!! } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.kt index e4b4c8db1f8..a36031007e2 100644 --- a/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.kt @@ -13,5 +13,5 @@ fun test(s: String): String { a checkType { _() } val b = TestClass { return s } - b checkType { _() } + b checkType { _() } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.kt index 291cbbcb677..fedc2368891 100644 --- a/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.kt @@ -11,5 +11,5 @@ fun test(s: String): String { a checkType { _() } val b = TestClass { return s } - b checkType { _() } + b checkType { _() } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.kt index 5e5d68efdfe..df74d11d940 100644 --- a/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.kt @@ -8,7 +8,7 @@ class TestClass { fun test(value: T, test: TestClass): T { val x = test { return value } - x checkType { _() } + x checkType { _() } return value } diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt index 21a02d26543..b648a682d34 100644 --- a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt @@ -5,5 +5,5 @@ val y get() = null!! fun foo() { x checkType { _() } - y checkType { _() } + y checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.kt index dc507807c72..cce34aa4cca 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.kt @@ -8,15 +8,15 @@ fun test(a: Int?, b: Int?) { } fun test(a: Int?, b: Int?, c: Int?) { - bar(if (a == null) return else if (b == null) return else c) + bar(if (a == null) return else if (b == null) return else c) } fun test(a: Any?, b: Any?, c: Int?) { - bar(if (a == null) if (b == null) c else return else return) + bar(if (a == null) if (b == null) c else return else return) } fun test(a: Int?, b: Any?, c: Int?) { - bar(if (a == null) { + bar(if (a == null) { return } else { if (b == null) { diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt index 9a2f6049ec0..c714d2bf47c 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt @@ -12,13 +12,13 @@ fun case_1() { } fun case_2() { - test_1 { null!! } - test_2 { null!! } + test_1 { null!! } + test_2 { null!! } } fun case_3() { - test_1 { throw Exception() } - test_2 { throw Exception() } + test_1 { throw Exception() } + test_2 { throw Exception() } } fun case_6() {