From 70c35f4186b56554bcb1cd17a89124e5a460297c Mon Sep 17 00:00:00 2001 From: "victor.petukhov" Date: Wed, 13 Mar 2019 16:28:51 +0300 Subject: [PATCH] Introduce warning about implicitly inferred Nothing as a type parameter ^KT-20849 Fixed --- .../jetbrains/kotlin/diagnostics/Errors.java | 2 + .../rendering/DefaultErrorMessages.java | 1 + .../resolve/PlatformConfiguratorBase.kt | 2 +- ...plicitNothingAsTypeParameterCallChecker.kt | 49 +++++++++++++++++++ .../nonLocalReturnUnreachable.kt | 4 +- .../tests/generics/projectionsScope/addAll.kt | 2 +- .../projectionsScope/typeMismatchInLambda.kt | 2 +- .../projectionsScope/typeParameterBounds.kt | 2 +- .../NoInferenceFromDeclaredBounds.kt | 2 +- .../ignoreConstraintFromImplicitInNothing.kt | 4 +- ...InCompanionObjectWithFunctionalArgument.kt | 2 +- ...citInvokeInObjectWithFunctionalArgument.kt | 2 +- ...plicitInvokeWithFunctionLiteralArgument.kt | 2 +- .../diagnostics/tests/j+k/flexibleNothing.kt | 2 +- .../inferenceFromGetters/nullAsNothing.kt | 2 +- .../implicitNothingAsTypeParameter.kt | 43 ++++++++++++++++ .../implicitNothingAsTypeParameterNI.kt | 49 +++++++++++++++++++ .../typeAliasConstructorCrazyProjections.kt | 2 +- .../testsWithStdLib/addAllProjection.kt | 4 +- .../tailCalls/nothingTypedSuspendFunction.kt | 2 +- .../reified/reifiedNothingSubstitution.kt | 2 +- .../smart-casts-sources/p-4/pos/1.12.kt | 4 +- .../contracts/analysis/smartcasts/pos/4.kt | 4 +- .../contracts/analysis/smartcasts/pos/8.kt | 2 +- .../checkers/DiagnosticsTestGenerated.java | 10 ++++ .../DiagnosticsUsingJavacTestGenerated.java | 10 ++++ 26 files changed, 188 insertions(+), 24 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index f4602f1ecab..5ba82a3871a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -743,6 +743,8 @@ public interface Errors { DiagnosticFactory0 TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT = DiagnosticFactory0.create(ERROR, SPECIAL_CONSTRUCT_TOKEN); + DiagnosticFactory0 IMPLICIT_NOTHING_AS_TYPE_PARAMETER = DiagnosticFactory0.create(WARNING); + // Reflection DiagnosticFactory1 EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 0a933eb0ea8..d15b57d1b78 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -959,6 +959,7 @@ public class DefaultErrorMessages { MAP.put(ILLEGAL_SUSPEND_PROPERTY_ACCESS, "Suspend property ''{0}'' should be accessed only from a coroutine or suspend function", NAME); MAP.put(ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, "Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope"); MAP.put(NON_MODIFIER_FORM_FOR_BUILT_IN_SUSPEND, "''suspend'' function can only be called in a form of modifier of a lambda: suspend { ... }"); + MAP.put(IMPLICIT_NOTHING_AS_TYPE_PARAMETER, "One of the type variables was implicitly inferred to Nothing. Please, specify type arguments explicitly to hide this warning."); MAP.put(RETURN_FOR_BUILT_IN_SUSPEND, "Using implicit label for this lambda is prohibited"); MAP.put(MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND, "Calls having a form of ''suspend {}'' are deprecated because ''suspend'' in the context will have a meaning of a modifier. Add empty argument list to the call: ''suspend() { ... }''"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index eb63507e10c..6b323ea7f27 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -42,7 +42,7 @@ private val DEFAULT_CALL_CHECKERS = listOf( ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, ApiVersionCallChecker, CoroutineSuspendCallChecker, BuilderFunctionsCallChecker, DslScopeViolationCallChecker, MissingDependencyClassChecker, CallableReferenceCompatibilityChecker(), LateinitIntrinsicApplicabilityChecker, - UnderscoreUsageChecker, AssigningNamedArgumentToVarargChecker(), + UnderscoreUsageChecker, AssigningNamedArgumentToVarargChecker(), ImplicitNothingAsTypeParameterCallChecker, PrimitiveNumericComparisonCallChecker, LambdaWithSuspendModifierCallChecker, UselessElvisCallChecker(), ResultTypeWithNullableOperatorsChecker(), NullableVarargArgumentCallChecker, NamedFunAsExpressionChecker, ContractNotAllowedCallChecker, ReifiedTypeParameterSubstitutionChecker(), TypeOfChecker diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt new file mode 100644 index 00000000000..c0e1808caaf --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.calls.checkers + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils +import org.jetbrains.kotlin.types.typeUtil.isNothing + +object ImplicitNothingAsTypeParameterCallChecker : CallChecker { + private val SPECIAL_FUNCTION_NAMES = ControlStructureTypingUtils.ResolveConstruct.values().map { it.specialFunctionName }.toSet() + + /* + * The warning isn't reported in cases where there are lambda among the function arguments, + * the return type of which is a type variable, that was inferred to Nothing. + * This corresponds to useful cases in which this report will not be helpful. + * + * E.g.: + * + * 1) Return if null: + * x?.let { return } + * + * 2) Implicit receiver to shorter code writing: + * x.run { + * println(inv()) + * return inv() + * } + */ + override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { + if (resolvedCall.candidateDescriptor.name !in SPECIAL_FUNCTION_NAMES && resolvedCall.call.typeArguments.isEmpty()) { + val lambdasFromArgumentsReturnTypes = + resolvedCall.candidateDescriptor.valueParameters.filter { it.type.isFunctionType } + .map { it.returnType?.arguments?.last()?.type }.toSet() + + val hasImplicitNothingExceptLambdaReturnTypes = resolvedCall.typeArguments.any { (unsubstitutedType, resultingType) -> + resultingType.isNothing() && unsubstitutedType.defaultType !in lambdasFromArgumentsReturnTypes + } + + if (hasImplicitNothingExceptLambdaReturnTypes) { + context.trace.report(Errors.IMPLICIT_NOTHING_AS_TYPE_PARAMETER.on(reportOn)) + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.kt index 804e44b34ae..14fbc01d280 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.kt @@ -13,13 +13,13 @@ fun doSomething() {} fun test2() { fun f(x: Any?) = x - f(null?.let { return }) + f(null?.let { return }) // false unreachable here doSomething() } fun test3(x: Any?): Boolean = - x?.let { + x?.let { return true } ?: false diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.kt index 8ee2dc801f5..f2733e73843 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.kt @@ -24,7 +24,7 @@ fun foo(x: MC) { x.addAll(mc()) x.addAllMC(mc()) - x.addAll(c()) + x.addAll(c()) x.addAll(c()) x.addAllInv(mc()) diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.kt index adca804ce06..31dcc4a698c 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.kt @@ -17,7 +17,7 @@ fun test(a: A, z: Out) { "" } a.bar { Out() } - a.bar { Out() } + a.bar { Out() } a.bar { z.id() } a.foo { diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt index ebe893a9bd3..cced4843383 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt @@ -16,7 +16,7 @@ fun foo2(a: A, b: A) { a.foo1(Out()) a.foo1<Out>(Out()) - a.foo1(Out()) + a.foo1(Out()) a.foo1(Out()) a.foo2(Inv()) diff --git a/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt index 579a0efd21c..2257b30c43b 100644 --- a/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt +++ b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt @@ -7,6 +7,6 @@ fun foo1() { fooT22() } -val n : Nothing = null.sure() +val n : Nothing = null.sure() fun T?.sure() : T = this!! diff --git a/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt b/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt index ad3b012468d..59cb039ada0 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/implicitInvokeInCompanionObjectWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.kt index afa2ef853b2..e4b4c8db1f8 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 b666faecc06..291cbbcb677 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 5d6bf1e3d34..5e5d68efdfe 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/j+k/flexibleNothing.kt b/compiler/testData/diagnostics/tests/j+k/flexibleNothing.kt index f5596d04f2e..3ced22857a0 100644 --- a/compiler/testData/diagnostics/tests/j+k/flexibleNothing.kt +++ b/compiler/testData/diagnostics/tests/j+k/flexibleNothing.kt @@ -10,7 +10,7 @@ public class TestClass { fun run() { val testClass = TestClass() // inferred as `set()`, return type is Nothing! - testClass.set("test", null) + testClass.set("test", null) // Should not be unreachable run() diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.kt index 733b649e084..21a02d26543 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/typeParameters/implicitNothingAsTypeParameter.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt new file mode 100644 index 00000000000..df1af2cd5ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST +// SKIP_TXT +// Issue: KT-20849 + +fun test_1(x: T): T = null as T +fun test_2(x: () -> T): T = null as T + +fun case_1() { + null?.run { return } + null!!.run { throw Exception() } +} + +fun case_2() { + test_1 { null!! } + test_2 { null!! } +} + +fun case_3() { + test_1 { throw Exception() } + test_2 { throw Exception() } +} + +fun case_6() { + null!! +} + +fun case_7(x: Boolean?) { + when (x) { + true -> throw Exception() + false -> throw Exception() + null -> throw Exception() + } +} + +fun something(): T = Any() as T + +class Context + +fun Any.decodeIn(typeFrom: Context): T = something() + +fun Any?.decodeOut(typeFrom: Context): T { + return this?.decodeIn(typeFrom) ?: error("") +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt new file mode 100644 index 00000000000..bf45435bb16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST +// !LANGUAGE: +NewInference +// SKIP_TXT +// Issue: KT-20849 + +fun test_1(x: T.() -> T): T = null as T +fun test_2(x: (T) -> T): T = null as T +fun test_3(x: T.(T) -> T): T = null as T +fun test_4(x: T.(T) -> List): T = null as T +fun test_5(): List = 10 as List +fun test_6(): Map = 10 as Map + +fun case_1() { + test_5() + test_6() + val x = test_6() +} + +fun case_2() { + test_1 { null!! } +} + +fun case_3() { + test_2 { null!! } +} + +fun case_4() { + test_3 { null!! } +} + +fun case_5() { + test_4 { null!! } +} + +fun case_6() { + test_1 { throw Exception() } +} + +fun case_7() { + test_2 { throw Exception() } +} + +fun case_8() { + test_3 { throw Exception() } +} + +fun case_9() { + test_4 { throw Exception() } +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.kt index fd3e6ec9b20..75da660f5ba 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.kt @@ -13,4 +13,4 @@ fun listOf(): List = null!! // since it has 'out' type projection in 'in' position. val test1 = BOutIn(listOf(), null!!) -val test2 = BInIn(listOf(), null!!) \ No newline at end of file +val test2 = BInIn(listOf(), null!!) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.kt b/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.kt index 73dfa29926d..14839d203c3 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.kt @@ -4,12 +4,12 @@ fun test(mc: MutableCollection) { mc.addAll(mc) mc.addAll(arrayListOf()) - mc.addAll(arrayListOf()) + mc.addAll(arrayListOf()) mc.addAll(listOf("")) mc.addAll(listOf("")) mc.addAll(listOf("")) - mc.addAll(emptyList()) + mc.addAll(emptyList()) mc.addAll(emptyList()) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction.kt index 3ae6f2f1c5b..fda16df7def 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction.kt @@ -3,7 +3,7 @@ import COROUTINES_PACKAGE.* import COROUTINES_PACKAGE.intrinsics.* -suspend fun suspendLogAndThrow(exception: Throwable): Nothing = suspendCoroutineUninterceptedOrReturn { c -> +suspend fun suspendLogAndThrow(exception: Throwable): Nothing = suspendCoroutineUninterceptedOrReturn { c -> c.resumeWithException(exception) COROUTINE_SUSPENDED } diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt index a52ba8b27fe..073a9d0bccd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.kt @@ -6,7 +6,7 @@ inline fun foo(block: () -> T): String = block().toString() inline fun javaClass(): Class = T::class.java fun box() { - val a = arrayOf(null!!) + val a = arrayOf(null!!) val b = Array<Nothing?>(5) { null!! } val c = foo() { null!! } val d = foo { null!! } diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt index cefb93d0ae3..f012662e00a 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt @@ -1661,12 +1661,12 @@ fun Nothing.case_63() { this.hashCode() hashCode() - apply { + apply { this hashCode() this.hashCode() } - also { + also { it it.hashCode() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/4.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/4.kt index 43123407801..e0676ea14ae 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/4.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/4.kt @@ -228,11 +228,11 @@ fun case_7(value_1: String?) { } when { value_1.case_7_10() == null -> println(value_1) - value_1.case_7_10() != null -> println(value_1) + value_1.case_7_10() != null -> println(value_1) } when { value_1.case_7_11() != null -> println(value_1) - value_1.case_7_11() == null -> println(value_1) + value_1.case_7_11() == null -> println(value_1) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/8.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/8.kt index 0b1de9ec267..f18818233a2 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/8.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/8.kt @@ -89,7 +89,7 @@ fun case_3(value_1: Int?, value_2: Any?) { if (!value_1.case_3(value_1, value_2 is Number?)) { println(value_2?.toByte()) println(value_1.inv()) - } else if (value_1.case_3(value_1, value_2 is Number?)) { + } else if (value_1.case_3(value_1, value_2 is Number?)) { println(value_1) } else { println(value_1.inv()) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 3fd8c0551dd..85c2b7cbcf0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -22150,6 +22150,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.kt"); } + @TestMetadata("implicitNothingAsTypeParameter.kt") + public void testImplicitNothingAsTypeParameter() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt"); + } + + @TestMetadata("implicitNothingAsTypeParameterNI.kt") + public void testImplicitNothingAsTypeParameterNI() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt"); + } + @TestMetadata("misplacedConstraints.kt") public void testMisplacedConstraints() throws Exception { runTest("compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 9108affa326..3dbd86f7d7e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -22070,6 +22070,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.kt"); } + @TestMetadata("implicitNothingAsTypeParameter.kt") + public void testImplicitNothingAsTypeParameter() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt"); + } + + @TestMetadata("implicitNothingAsTypeParameterNI.kt") + public void testImplicitNothingAsTypeParameterNI() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameterNI.kt"); + } + @TestMetadata("misplacedConstraints.kt") public void testMisplacedConstraints() throws Exception { runTest("compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.kt");