From 2ecb6733eda0435178ef220b0b07a09ec16f5078 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Thu, 1 Apr 2021 11:44:47 -0700 Subject: [PATCH] FIR checker: warn unnecessary non-null assertions --- .../positive/exhaustiveWhenAndDNNType.kt | 4 +- .../testData/resolve/whenElse.kt | 6 +-- .../testData/resolve/whenExpressionType.kt | 8 ++-- .../testData/resolveWithStdlib/hashSet.kt | 4 +- .../problems/SpecialCallsWithLambdas.kt | 2 +- .../diagnostics/FirDiagnosticsList.kt | 5 ++ .../fir/analysis/diagnostics/FirErrors.kt | 3 ++ .../expression/FirCheckNotNullCallChecker.kt | 46 +++++++++++++++++++ .../diagnostics/FirDefaultErrorMessages.kt | 6 +++ .../fir/checkers/CommonExpressionCheckers.kt | 1 + .../generic/specialCalls.fir.kt | 2 +- .../withQuestionMarks.fir.kt | 12 ++--- .../deadCodeInInnerExpressions.fir.kt | 4 +- .../deadCode/deadCodeInUnaryExpr.fir.kt | 4 +- .../lambdasInExclExclAndElvis.fir.kt | 4 +- .../ArrayGetSetConvention.fir.kt | 2 +- .../dataFlowInfoTraversal/ArrayIndices.fir.kt | 2 +- .../dataFlowInfoTraversal/ExclExcl.fir.kt | 8 ++-- .../dataFlowInfoTraversal/IfThenElse.fir.kt | 2 +- .../LabeledFunctionLiterals.fir.kt | 2 +- .../specialCallsWithCallableReferences.fir.kt | 14 +++--- ...allableReferencesDontRewriteAtSlice.fir.kt | 6 +-- ...allsWithCallableReferencesErrorType.fir.kt | 14 +++--- .../specialCallsWithLambdas.fir.kt | 10 ++-- .../nestedCalls/makeNullableIfSafeCall.fir.kt | 22 ++++----- .../inference/regressions/kt36342.fir.kt | 2 +- .../specialCallsWithCallableReferences.fir.kt | 14 +++--- .../AssertNotNull.fir.kt | 24 +++++----- .../QualifiedExpressionNullability.fir.kt | 12 ++--- .../nullabilityAndSmartCasts/kt2164.fir.kt | 10 ++-- .../nullabilityAndSmartCasts/kt2176.fir.kt | 2 +- .../nullabilityAndSmartCasts/kt2212.fir.kt | 2 +- .../nullabilityAndSmartCasts/kt2216.fir.kt | 2 +- .../nullabilityAndSmartCasts/kt2234.fir.kt | 4 +- .../nullabilityAndSmartCasts/kt2336.fir.kt | 2 +- .../unnecessaryNotNullAssertion.fir.kt | 8 ++-- .../definitelyNotNullWithNullableBound.fir.kt | 4 +- ...lAssertOnTypeWithNullableUpperBound.fir.kt | 4 +- .../notNullAssertion.fir.kt | 40 ---------------- .../nullabilityWarnings/notNullAssertion.kt | 1 + .../notNullAssertionInCall.fir.kt | 27 ----------- .../notNullAssertionInCall.kt | 1 + ...ullTypeMarkedWithNullableAnnotation.fir.kt | 2 +- .../tests/regressions/kt10843.fir.kt | 2 +- .../resolve/callableReferenceInCST.fir.kt | 2 +- ...kt4204-completeNestedCallsForInvoke.fir.kt | 24 ---------- .../kt4204-completeNestedCallsForInvoke.kt | 1 + .../exclExclAsCall.fir.kt | 2 +- .../tests/smartCasts/elvis/basicOn.fir.kt | 4 +- .../tests/smartCasts/inference/kt1355.fir.kt | 2 +- .../tests/smartCasts/inference/kt2851.fir.kt | 2 +- .../tests/smartCasts/kt2865.fir.kt | 4 +- .../smartCasts/safecalls/argument.fir.kt | 6 --- .../tests/smartCasts/safecalls/argument.kt | 1 + .../smartCasts/safecalls/propertyChain.fir.kt | 4 +- .../testsWithStdLib/assert/safeCall.fir.kt | 4 +- .../testsWithStdLib/regression/kt10001.fir.kt | 2 +- .../p-2/pos/1.1.fir.kt | 10 ++-- .../analysis/smartcasts/pos/14.fir.kt | 2 +- .../analysis/smartcasts/pos/2.fir.kt | 2 +- .../diagnostics/notLinked/dfa/neg/19.fir.kt | 2 +- .../diagnostics/notLinked/dfa/neg/20.fir.kt | 2 +- .../diagnostics/notLinked/dfa/pos/30.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/36.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/38.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/40.fir.kt | 2 +- .../diagnostics/notLinked/dfa/pos/51.fir.kt | 8 ++-- .../diagnostics/notLinked/dfa/pos/55.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/69.fir.kt | 2 +- .../diagnostics/KtFirDataClassConverters.kt | 19 ++++++++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 13 ++++++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 22 +++++++++ 72 files changed, 268 insertions(+), 246 deletions(-) create mode 100644 compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCheckNotNullCallChecker.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveWhenAndDNNType.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveWhenAndDNNType.kt index b2fb14b0bf3..be8412c5e42 100644 --- a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveWhenAndDNNType.kt +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveWhenAndDNNType.kt @@ -11,7 +11,7 @@ fun takeB(b: B) {} fun test_1() { val flag = SomeEnum.A1 - val b: B = when (flag!!) { + val b: B = when (flag!!) { SomeEnum.A1 -> B() SomeEnum.A2 -> B() } @@ -21,7 +21,7 @@ fun test_1() { fun test_2() { val flag = SomeEnum.A1 - val b = when (flag!!) { + val b = when (flag!!) { SomeEnum.A1 -> B() SomeEnum.A2 -> B() } diff --git a/compiler/fir/analysis-tests/testData/resolve/whenElse.kt b/compiler/fir/analysis-tests/testData/resolve/whenElse.kt index 8dcd09a23e6..b0c7497d497 100644 --- a/compiler/fir/analysis-tests/testData/resolve/whenElse.kt +++ b/compiler/fir/analysis-tests/testData/resolve/whenElse.kt @@ -16,7 +16,7 @@ fun get(f: Boolean) = if (f) {A.A1} else {""} fun case2() { val flag: Any = get(false) //string - val l1 = when (flag!!) { // should be NO_ELSE_IN_WHEN + val l1 = when (flag!!) { // should be NO_ELSE_IN_WHEN A.A1 -> B() A.A2 -> B() } @@ -30,7 +30,7 @@ fun get(f: Boolean) = if (f) {A.A1} else {""} fun case2() { val flag: Any = get(true) //A - val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN + val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN A.A1 -> B() A.A2 -> B() } @@ -44,7 +44,7 @@ fun get(f: Boolean) = if (f) {A.A1} else {""} fun case3() { val flag = "" //A - val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN + val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN A.A1 -> B() //should be INCOMPATIBLE_TYPES A.A2 -> B() //should be INCOMPATIBLE_TYPES } diff --git a/compiler/fir/analysis-tests/testData/resolve/whenExpressionType.kt b/compiler/fir/analysis-tests/testData/resolve/whenExpressionType.kt index 3b4917099dc..b4944831f8e 100644 --- a/compiler/fir/analysis-tests/testData/resolve/whenExpressionType.kt +++ b/compiler/fir/analysis-tests/testData/resolve/whenExpressionType.kt @@ -13,7 +13,7 @@ class C(val b: B) // TESTCASE NUMBER: 1 fun case1() { val flag = A.A1 - val l0: B = when (flag!!) { + val l0: B = when (flag!!) { A.A1 -> B() A.A2 -> B() } @@ -34,7 +34,7 @@ fun case2() { fun case3() { val flag = A.A1 - val l1 = when (flag!!) { + val l1 = when (flag!!) { A.A1 -> B() A.A2 -> B() } @@ -68,7 +68,7 @@ fun case5() { // TESTCASE NUMBER: 6 fun case6() { val flag: Any = A.A1 - val l1 = when (flag!!) { + val l1 = when (flag!!) { A.A1 -> B() A.A2 -> B() else -> B() @@ -91,7 +91,7 @@ fun case7() { // TESTCASE NUMBER: 8 fun case8() { val flag: Any = A.A1 - val l1: B = when (flag!!) { + val l1: B = when (flag!!) { A.A1 -> B() A.A2 -> B() else -> B() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.kt index 7e3289dd9ed..922c1ec5e52 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.kt @@ -16,5 +16,5 @@ fun foo() { var c: MutableSet? = null c = HashSet() - c!!.d = produce() -} \ No newline at end of file + c!!.d = produce() +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/SpecialCallsWithLambdas.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/SpecialCallsWithLambdas.kt index 17c9047281f..390025062a0 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/SpecialCallsWithLambdas.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/SpecialCallsWithLambdas.kt @@ -1,4 +1,4 @@ fun foo() { - val inv = {{}}!! + val inv = {{}}!! val bar = {{}} } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index b8e021cef6f..194440b0088 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -560,6 +560,11 @@ object DIAGNOSTICS_LIST : DiagnosticList() { parameter("rhs") } // TODO: val UNEXPECTED_SAFE_CALL by ... + val UNNECESSARY_NOT_NULL_ASSERTION by warning(PositioningStrategy.OPERATOR) { + parameter("receiverType") + } + val NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION by warning(PositioningStrategy.OPERATOR) + val NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE by warning(PositioningStrategy.OPERATOR) } val WHEN_EXPRESSIONS by object : DiagnosticGroup("When expressions") { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index be0ac5b710c..81e9e4e5281 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -331,6 +331,9 @@ object FirErrors { val UNSAFE_IMPLICIT_INVOKE_CALL by error1(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val UNSAFE_INFIX_CALL by error3(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val UNSAFE_OPERATOR_CALL by error3(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) + val UNNECESSARY_NOT_NULL_ASSERTION by warning1(SourceElementPositioningStrategies.OPERATOR) + val NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION by warning0(SourceElementPositioningStrategies.OPERATOR) + val NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE by warning0(SourceElementPositioningStrategies.OPERATOR) // When expressions val NO_ELSE_IN_WHEN by error1>(SourceElementPositioningStrategies.WHEN_EXPRESSION) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCheckNotNullCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCheckNotNullCallChecker.kt new file mode 100644 index 00000000000..e4838f14639 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCheckNotNullCallChecker.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir.analysis.checkers.expression + +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction +import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess +import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall +import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType +import org.jetbrains.kotlin.fir.types.* + +object FirCheckNotNullCallChecker : FirBasicExpressionChecker() { + override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) { + if (expression !is FirCheckNotNullCall) return + + val argument = expression.argumentList.arguments.singleOrNull() ?: return + if (argument is FirAnonymousFunction && argument.isLambda) { + reporter.reportOn(expression.source, FirErrors.NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, context) + return + } + if (argument is FirCallableReferenceAccess) { + reporter.reportOn(expression.source, FirErrors.NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE, context) + return + } + // TODO: use of Unit is subject to change. + // See BodyResolveComponents.typeForQualifier in ResolveUtils.kt which returns Unit for no value type. + if (argument is FirResolvedQualifier && argument.typeRef.isUnit) { + // Would be reported as NO_COMPANION_OBJECT + return + } + + val type = argument.typeRef.coneType.fullyExpandedType(context.session) + + if (!type.canBeNull) { + reporter.reportOn(expression.source, FirErrors.UNNECESSARY_NOT_NULL_ASSERTION, type, context) + } + } +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index f3585c62a4a..3c7a86f6384 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -149,6 +149,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOTHING_TO_OVERRI import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_AN_ANNOTATION_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_LOOP_LABEL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_SUPERTYPE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NO_ELSE_IN_WHEN import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NO_GET_METHOD import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NO_SET_METHOD @@ -217,6 +219,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.TYPE_PARAMETER_IS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.TYPE_PARAMETER_ON_LHS_OF_DOT import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNINITIALIZED_VARIABLE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNNECESSARY_LATEINIT +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNNECESSARY_NOT_NULL_ASSERTION import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNRESOLVED_LABEL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNRESOLVED_REFERENCE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.UNSAFE_CALL @@ -745,6 +748,9 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { TO_STRING, FIR ) + map.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE) + map.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression") + map.put(NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE, "Non-null assertion (!!) is called on a callable reference expression") // When expressions map.put(NO_ELSE_IN_WHEN, "''when'' expression must be exhaustive, add necessary {0}", WHEN_MISSING_CASES) diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonExpressionCheckers.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonExpressionCheckers.kt index 07907307d77..567e3888526 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonExpressionCheckers.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonExpressionCheckers.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.expression.* object CommonExpressionCheckers : ExpressionCheckers() { override val basicExpressionCheckers: Set = setOf( FirAnonymousFunctionChecker, + FirCheckNotNullCallChecker, FirGetClassCallChecker, ) diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt index 1c68ab510fd..cd4fc8dce3f 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt @@ -17,7 +17,7 @@ fun test() { else -> ::baz }) - val x5: (Int) -> Int = bar(::baz!!) + val x5: (Int) -> Int = bar(::baz!!) (if (true) ::baz else ::baz)(1) } diff --git a/compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.fir.kt b/compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.fir.kt index 8b84f6a1110..75222ee926d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.fir.kt @@ -10,18 +10,18 @@ fun main() { val x4 = logger?::info?::print?::print?::print?::print?::print?::print?::print?::print?::print?::print val x5 = logger::info?::print?::print?::print?::print?::print?::print?::print?::print?::print?::print val x6 = logger!!::info?::print?::print - val x7 = logger::info!!::print?::print - val x8 = logger?::info!!::print?::print + val x7 = logger::info!!::print?::print + val x8 = logger?::info!!::print?::print val x9 = logger!!::info?::print?::print - val x10 = logger::info?::print!!::print - val x11 = logger!!::info!!::print!!::print - val x12 = logger?::info!!::print!!::print + val x10 = logger::info?::print!!::print + val x11 = logger!!::info!!::print!!::print + val x12 = logger?::info!!::print!!::print val x13 = 42?::unresolved?::print val x14 = logger?!!::info?::print?::print val x15 = logger::info?!!::print?::print val x16 = logger!!?::info?::print?::print - val x17 = logger::info!!?::print?::print + val x17 = logger::info!!?::print?::print // It must be OK val x18 = String?::hashCode ?: ::foo diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt index 6263d0d7291..3048ba34877 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt @@ -2,7 +2,7 @@ fun testCompound() { operator fun Nothing.get(i: Int) {} - todo()!![12] + todo()!![12] } fun testCompound1() { @@ -10,4 +10,4 @@ fun testCompound1() { (todo() * "")[1] } -fun todo(): Nothing = throw Exception() \ No newline at end of file +fun todo(): Nothing = throw Exception() diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt index bd53f349b08..1f14c0fe2c9 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt @@ -9,7 +9,7 @@ fun testPostfixWithCall(n: Nothing) { } fun testPostfixSpecial() { - todo()!! + todo()!! } -fun todo(): Nothing = throw Exception() \ No newline at end of file +fun todo(): Nothing = throw Exception() diff --git a/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt index 438b7887dd8..991d512bd56 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt @@ -4,8 +4,8 @@ fun use(a: Any?) = a fun test() { - { }!! - use({ }!!); + { }!! + use({ }!!); // KT-KT-9070 { } ?: 1 diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt index 17176604658..3d75f2ecfca 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt @@ -6,7 +6,7 @@ interface G { } fun foo1(a: Int?, b: G) { - b[a!!, a!!] = a + b[a!!, a!!] = a checkSubtype(a) } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt index 1fc7a3424b4..79a073f284e 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt @@ -1,7 +1,7 @@ // !CHECK_TYPE fun foo1(a: Int?, b: Array>) { - b[a!!][a!!] = a + b[a!!][a!!] = a checkSubtype(a) } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt index 6280b743bfc..02ddbc32ee5 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt @@ -2,7 +2,7 @@ fun bar(x: Int) = x + 1 fun f1(x: Int?) { bar(x) - if (x != null) bar(x!!) + if (x != null) bar(x!!) if (x == null) bar(x!!) } @@ -11,13 +11,13 @@ fun f2(x: Int?) { } fun f3(x: Int?) { - if (x != null) bar(x!!) else x!! + if (x != null) bar(x!!) else x!! } fun f4(x: Int?) { - if (x == null) x!! else bar(x!!) + if (x == null) x!! else bar(x!!) } fun f5(x: Int?) { - if (x == null) else bar(x!!) + if (x == null) else bar(x!!) } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt index a5c46064d8c..ab045d4abcc 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt @@ -26,5 +26,5 @@ fun foo() { if (z != null) bar(z) bar(z) bar(z!!) - if (z != null) bar(z!!) + if (z != null) bar(z!!) } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt index 66d13d14d6f..3ed2055c36e 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt @@ -11,6 +11,6 @@ fun foo(b: B, f: () -> T): T = f() fun test(c: C) { foo(c) f@ { - c!! + c!! } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt index f08d4ca064d..2b0c0d2879e 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt @@ -388,49 +388,49 @@ fun poll66(): Flow { fun poll7(): Flow { return flow { - val inv = ::bar!! + val inv = ::bar!! inv() } } fun poll71(): Flow { return flow { - val inv = ::bar2!! + val inv = ::bar2!! inv() } } fun poll72(): Flow { return flow { - val inv = ::bar3!! + val inv = ::bar3!! inv() } } fun poll73(): Flow { return flow { - val inv = ::bar4!! + val inv = ::bar4!! inv } } fun poll74(): Flow { return flow { - val inv = ::bar5!! + val inv = ::bar5!! inv } } fun poll75(): Flow { return flow { - val inv = ::Foo6!! + val inv = ::Foo6!! inv } } fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontRewriteAtSlice.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontRewriteAtSlice.fir.kt index 6564070e406..0a2bee8e5fc 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontRewriteAtSlice.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontRewriteAtSlice.fir.kt @@ -36,21 +36,21 @@ class Flow(private val block: suspend FlowCollector.() -> Unit) fun poll71(): Flow { return flow { - val inv = ::bar2!! + val inv = ::bar2!! inv() } } fun poll73(): Flow { return flow { - val inv = ::bar4!! + val inv = ::bar4!! inv } } fun poll75(): Flow { return flow { - val inv = ::Foo6!! + val inv = ::Foo6!! inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt index 6a28975caa9..2ab1539f80d 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt @@ -37,49 +37,49 @@ class Flow(private val block: suspend FlowCollector.() -> Unit) fun poll7(): Flow { return flow { - val inv = ::bar!! + val inv = ::bar!! inv() } } fun poll71(): Flow { return flow { - val inv = ::bar2!! + val inv = ::bar2!! inv() } } fun poll72(): Flow { return flow { - val inv = ::bar3!! + val inv = ::bar3!! inv() } } fun poll73(): Flow { return flow { - val inv = ::bar4!! + val inv = ::bar4!! inv } } fun poll74(): Flow { return flow { - val inv = ::bar5!! + val inv = ::bar5!! inv } } fun poll75(): Flow { return flow { - val inv = ::Foo6!! + val inv = ::Foo6!! inv } } fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.fir.kt index ef0c7ae3442..b5a719de899 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.fir.kt @@ -119,28 +119,28 @@ fun poll5(): Flow { fun poll7(): Flow { return flow { - val inv = {}!! + val inv = {}!! inv() } } fun poll71(): Flow { return flow { - val inv = {1f}!! + val inv = {1f}!! inv() } } fun poll72(): Flow { return flow { - val inv = {{}}!! + val inv = {{}}!! inv() } } fun poll73(): Flow { return flow { - val inv = ({})!! + val inv = ({})!! inv } } @@ -189,7 +189,7 @@ fun poll85(): Flow { fun poll86(): Flow { return flow { - val inv = {({"1"})}!! in setOf({({"1f"})}!!) + val inv = {({"1"})}!! in setOf({({"1f"})}!!) inv() } } diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt index 7c4b7fe3e78..bb1c0fe22f1 100644 --- a/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt @@ -11,23 +11,23 @@ interface B { fun test(u: A?, x: A?, y: A?, z: A?, w: A, v: A?) { u?.b?.foo()!! // was UNNECESSARY_SAFE_CALL everywhere, because result type (of 'foo()') wasn't made nullable - u!!.b?.foo()!! - x?.b!!.foo()!! + u!!.b?.foo()!! + x?.b!!.foo()!! // x?.b is not null - x!!.b!!.foo()!! + x!!.b!!.foo()!! y?.nb?.foo()!! y!!.nb?.foo()!! - z?.nb!!.foo()!! + z?.nb!!.foo()!! // z?.nb is not null - z!!.nb!!.foo()!! + z!!.nb!!.foo()!! - w.b?.foo()!! - w.b!!.foo()!! + w.b?.foo()!! + w.b!!.foo()!! w.nb?.foo()!! - w.nb!!.foo()!! + w.nb!!.foo()!! - v!!.b.foo()!! + v!!.b.foo()!! } fun B?.bar(): Int = 1 @@ -36,6 +36,6 @@ fun B?.baz(): Int? = 1 fun doInt(i: Int) = i fun test(a: A?) { - doInt(a?.b.bar()!!) + doInt(a?.b.bar()!!) doInt(a?.b.baz()!!) -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt index ce7dd68d053..e91f493dd55 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt @@ -5,7 +5,7 @@ import java.lang.Exception fun id(arg: K): K = arg fun test() { - id(unresolved)!! + id(unresolved)!! unresolved!!!! try { id(unresolved) diff --git a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt index 3b1681ff5d3..bc3a4c9cf4c 100644 --- a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt @@ -234,37 +234,37 @@ fun poll66() { } fun poll7() { - val inv = ::bar!! + val inv = ::bar!! inv() } fun poll71() { - val inv = ::bar2!! + val inv = ::bar2!! inv() } fun poll72() { - val inv = ::bar3!! + val inv = ::bar3!! inv() } fun poll73() { - val inv = ::bar4!! + val inv = ::bar4!! inv } fun poll74() { - val inv = ::bar5!! + val inv = ::bar5!! inv } fun poll75() { - val inv = ::Foo6!! + val inv = ::Foo6!! inv } fun poll76() { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt index 88c1df2e526..c30dd5c1fd0 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt @@ -5,35 +5,35 @@ fun main() { val a : Int? = null val b : Int? = null checkSubtype(a!!) - a!! + 2 - a!!.plus(2) - a!!.plus(b!!) - 2.plus(b!!) - 2 + b!! + a!! + 2 + a!!.plus(2) + a!!.plus(b!!) + 2.plus(b!!) + 2 + b!! val c = 1 - c!! + c!! val d : Any? = null if (d != null) { - d!! + d!! } // smart cast isn't needed, but is reported due to KT-4294 if (d is String) { - d!! + d!! } if (d is String?) { if (d != null) { - d!! + d!! } if (d is String) { - d!! + d!! } } - val f : String = a!! - checkSubtype(a!!) + val f : String = a!! + checkSubtype(a!!) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt index afbacdf9d23..1d567c4e277 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt @@ -10,7 +10,7 @@ fun main() { x.foo(y) x!!.foo(y) x.foo(y!!) - x!!.foo(y!!) + x!!.foo(y!!) val a: Foo? = null val b: Foo? = null @@ -19,12 +19,12 @@ fun main() { a.foo(b.foo(c)) a!!.foo(b.foo(c)) a.foo(b!!.foo(c)) - a!!.foo(b!!.foo(c)) + a!!.foo(b!!.foo(c)) a.foo(b.foo(c!!)) - a!!.foo(b.foo(c!!)) - a.foo(b!!.foo(c!!)) - a!!.foo(b!!.foo(c!!)) + a!!.foo(b.foo(c!!)) + a.foo(b!!.foo(c!!)) + a!!.foo(b!!.foo(c!!)) val z: Foo? = null - z!!.foo(z!!) + z!!.foo(z!!) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt index f8234379d56..0cc13b612c3 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt @@ -11,7 +11,7 @@ fun main() { if (x != null) { foo(x) - foo(x!!) + foo(x!!) foo(x) } @@ -19,7 +19,7 @@ fun main() { if (x != null) { foo(x) - foo(x!!) + foo(x!!) foo(x) } else { foo(x) @@ -28,12 +28,12 @@ fun main() { } foo(x) - foo(x!!) + foo(x!!) foo(x) val y: Int? = null y!! - y!! + y!! foo(y) - foo(y!!) + foo(y!!) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt index ea93bce992c..9e1f15913f1 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt @@ -11,7 +11,7 @@ fun f1(a: String?) { } fun f2(a: String) { - a!! + a!! checkSubtype(a) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt index 5e549d859dd..b4ebeb2fc3e 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt @@ -4,5 +4,5 @@ package kt2212 fun main() { val x: Int? = 1 if (x == null) return - System.out.println(x.plus(x!!)) + System.out.println(x.plus(x!!)) } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt index 145f0c0349d..d1621f806a5 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt @@ -11,7 +11,7 @@ fun foo() { bar(if (x != null) x else return, x) x + 2 - bar(x, x!!) + bar(x, x!!) val y: Int? = 0 val z: Int? = 0 diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt index fe807690557..7ac48089db5 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt @@ -11,14 +11,14 @@ class Pair(val a: A, val b: B) fun main() { val d : Long = 1 val period : Int? = null - if (period != null) Pair(d, checkSubtype(period!!)) else Pair(d, 1) + if (period != null) Pair(d, checkSubtype(period!!)) else Pair(d, 1) if (period != null) Pair(d, checkSubtype(period)) else Pair(d, 1) } fun foo() { val x : Int? = 3 if (x != null) { - val u = checkSubtype(x!!) + val u = checkSubtype(x!!) val y = checkSubtype(x) val z : Int = y } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt index aaf1a9743cb..da5f20b2a2a 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt @@ -3,7 +3,7 @@ fun main() { if (b != null) { if (!b) {} // OK if (b) {} // Error: Condition must be of type kotlin.Boolean, but is of type kotlin.Boolean? - if (b!!) {} // WARN: Unnecessary non-null assertion (!!) on a non-null receiver of type kotlin.Boolean? + if (b!!) {} // WARN: Unnecessary non-null assertion (!!) on a non-null receiver of type kotlin.Boolean? foo(b) // OK } } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt index a99f24208ba..b5f9e05f811 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt @@ -17,8 +17,8 @@ fun test() { takeNotNull(dependOn(dependOn(x!!))) if (x != null) { - takeNotNull(dependOn(x)!!) - takeNotNull(dependOn(dependOn(x))!!) - takeNotNull(dependOn(dependOn(x)!!)) + takeNotNull(dependOn(x)!!) + takeNotNull(dependOn(dependOn(x))!!) + takeNotNull(dependOn(dependOn(x)!!)) } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.fir.kt index def41f7f059..be145dfbf1e 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.fir.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.fir.kt @@ -6,7 +6,7 @@ fun makeDefinitelyNotNull(arg: D?): D = TODO() fun test(arg: N) { makeDefinitelyNotNull(arg) ?: 1 - makeDefinitelyNotNull(arg)!! + makeDefinitelyNotNull(arg)!! makeDefinitelyNotNull(arg)?.toInt() @@ -14,4 +14,4 @@ fun test(arg: N) { null -> false else -> true } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt index c687da5c046..fcce0275ffd 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt @@ -1,14 +1,14 @@ // !WITH_NEW_INFERENCE fun test(t: T): T { if (t != null) { - return t!! + return t!! } return t!! } fun T.testThis(): String { if (this != null) { - return this!!.toString() + return this!!.toString() } return this!!.toString() } diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt deleted file mode 100644 index c388c511f33..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt +++ /dev/null @@ -1,40 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -SENSELESS_COMPARISON -UNUSED_PARAMETER - -// FILE: J.java - -import org.jetbrains.annotations.*; - -public class J { - @NotNull - public static J staticNN; - @Nullable - public static J staticN; - public static J staticJ; -} - -// FILE: k.kt - -fun test() { - // @NotNull platform type - val platformNN = J.staticNN - // @Nullable platform type - val platformN = J.staticN - // platform type with no annotation - val platformJ = J.staticJ - - if (platformNN != null) { - platformNN!! - } - - if (platformN != null) { - platformN!! - } - - if (platformJ != null) { - platformJ!! - } - - platformNN!! - platformN!! - platformJ!! -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.kt index 75a31645695..c49402d4d7a 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION -SENSELESS_COMPARISON -UNUSED_PARAMETER // FILE: J.java diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt deleted file mode 100644 index 51129def4ac..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt +++ /dev/null @@ -1,27 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -// FILE: J.java - -import org.jetbrains.annotations.*; - -public class J { - @NotNull - public static J staticNN; -} - -// FILE: k.kt - -fun test() { - // @NotNull platform type - val platformNN = J.staticNN - - foo(platformNN!!) - val bar = Bar() - bar(platformNN!!) -} - -fun foo(a: Any) {} - -class Bar { - operator fun invoke(a: Any) {} -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.kt index a854d652825..91e5a5e32ea 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: J.java diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt index 5e68aea15f6..9e75d7e9557 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt @@ -15,7 +15,7 @@ fun list(j: J): Any { a?.get(0) if (a == null) {} - a!! + a!! a.get(0) return a diff --git a/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt index d8b434aa4a4..4fc6089a8a8 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt @@ -5,4 +5,4 @@ fun lambda(x : Int?) = x?.let if (y > 0) return@l x y -}!! +}!! diff --git a/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt index c9b2f2f93af..5ce865ec935 100644 --- a/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt @@ -28,7 +28,7 @@ fun testElvis(x: Any?) { } fun testExclExcl() { - val y = :: unresolved!! + val y = :: unresolved!! } fun testTry() { diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt deleted file mode 100644 index 0bf25a44277..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt +++ /dev/null @@ -1,24 +0,0 @@ -//KT-4204 ConstraintSystem erased after resolution completion -package c - -public abstract class TestBug1() { - - public fun m3(position: Int) { - position(m1().second!!) - } - - public fun m4(position: (Int)->Int) { - position(m1().second) - } - - private abstract fun m1(): Pair - - private fun position(p: Int) {} - -} - -//from library -public class Pair ( - public val first: A, - public val second: B -) diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.kt index 76b7db75068..ea9316e2da6 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL //KT-4204 ConstraintSystem erased after resolution completion package c diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt index 50e7fc4e026..08c10b71599 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt @@ -25,5 +25,5 @@ fun testDataFlowInfoAfterExclExcl(a: Int?) { } fun testUnnecessaryExclExcl(a: Int) { - doInt(a!!) //should be warning + doInt(a!!) //should be warning } diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt index dacb3b62b03..38f0f15dc5e 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt @@ -27,13 +27,13 @@ fun bar(o: Any) { } else { - order!!.doSomething() + order!!.doSomething() } if (order?.notExpired() ?: true) { } else { - order!!.doSomething() + order!!.doSomething() } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt index 4e0ea846b5b..f98867b21d0 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt @@ -25,7 +25,7 @@ public data class Tag(public var tagName: String) { attributes.remove("id") } else { - attributes["id"] = value!! + attributes["id"] = value!! attributes["id"] = value } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt index 404e80ba754..e679d707fba 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt @@ -5,7 +5,7 @@ fun main() { val value: String? = "" if (value != null) { foo(Pair("val", value)) - foo(Pair("val", value!!)) + foo(Pair("val", value!!)) foo(Pair("val", value)) } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt index b45e99f82f0..8bb32d4e48a 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt @@ -3,10 +3,10 @@ operator fun MutableMap.set(k: K, v: V) {} fun foo(a: MutableMap, x: String?) { a[x!!] = x - a[x] = x!! + a[x] = x!! } fun foo1(a: MutableMap, x: String?) { a[x] = x!! - a[x!!] = x + a[x!!] = x } diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt deleted file mode 100644 index 0e78b7fcbc0..00000000000 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -fun calc(x: List?): Int { - // After KT-5840 fix !! assertion should become unnecessary here - x?.get(x!!.size - 1) - // x?. or x!! above should not provide smart cast here - return x.size -} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.kt index 049e007c508..ac098ffed0c 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun calc(x: List?): Int { // After KT-5840 fix !! assertion should become unnecessary here x?.get(x!!.size - 1) diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt index 1cf8604ce26..de23de46613 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt @@ -10,5 +10,5 @@ fun foo(y: MyClass?): Int { fun bar(y: MyClass?) { y?.x!!.length // !! is NOT necessary here, because y?.x != null - y!!.x -} \ No newline at end of file + y!!.x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt index dbacaa18056..d5abe132680 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt @@ -10,7 +10,7 @@ fun test1(s: String?) { fun test2(s: String?) { assert(s!!.isEmpty()) - s!!.length + s!!.length } fun test3(s: String?) { @@ -27,7 +27,7 @@ fun test4() { fun test5() { val s: String? = null; assert(s!!.isEmpty()) - s!!.length + s!!.length } fun test6() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt index 1f2bc054fdf..f8279f4fec2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt @@ -1,5 +1,5 @@ fun foo1(p: Pair): Int { - if (p.first != null) return p.first!! + if (p.first != null) return p.first!! return p.second } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-2/pos/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-2/pos/1.1.fir.kt index 443aa03c8c4..43c6afbf0c1 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-2/pos/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-2/pos/1.1.fir.kt @@ -20,26 +20,26 @@ import libModule.* // TESTCASE NUMBER: 1 fun case1() { - val res = JavaClass.FALSE!! + val res = JavaClass.FALSE!! } // TESTCASE NUMBER: 2 fun case2() { - val x = JavaClass.obj!! + val x = JavaClass.obj!! } // TESTCASE NUMBER: 3 fun case3() { val a = false - val x = a!! + val x = a!! } // TESTCASE NUMBER: 4 fun case4() { - val x = "weds"!! + val x = "weds"!! } // TESTCASE NUMBER: 5 fun case5(nothing: Nothing) { - val y = nothing!! + val y = nothing!! } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt index 898e0aa9c0d..041d5ba4639 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt @@ -55,7 +55,7 @@ fun case_1(value_1: Int?) { // TESTCASE NUMBER: 2 fun case_2(value_1: Int?) { - if (!contracts.case_2(value_1)!!) { + if (!contracts.case_2(value_1)!!) { value_1.inv() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/2.fir.kt index fe59b28d9a9..3afea34242b 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/2.fir.kt @@ -159,6 +159,6 @@ class case_10_class { */ fun case_11(value_1: Any?, value_2: Any?, value_3: Any?) { funWithReturnsAndInvertCondition(value_1 !is String || value_2 !is Number || value_3 !is Any?) - println(value_1!!.length) + println(value_1!!.length) println(value_2?.toByte()) } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/19.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/19.fir.kt index 9cf9800100c..efb60737fb0 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/19.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/19.fir.kt @@ -339,7 +339,7 @@ fun case_25(x: Boolean?) { */ fun case_26(x: Boolean?) { while (true) { - for (i in listOf(break, x!!, x!!)) { + for (i in listOf(break, x!!, x!!)) { } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/20.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/20.fir.kt index 27c1f8c659a..b9e440ebfbe 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/20.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/20.fir.kt @@ -339,7 +339,7 @@ fun case_25(x: Boolean?) { */ fun case_26(x: Boolean?) { while (true) { - for (i in listOf(break, x as Boolean, x!!)) { + for (i in listOf(break, x as Boolean, x!!)) { } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/30.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/30.fir.kt index c909df2713c..d19375bc06d 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/30.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/30.fir.kt @@ -98,7 +98,7 @@ fun case_6(x: Class?) { * ISSUES: KT-30376 */ fun case_7(x: Class) { - if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) { + if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) { x x.prop_8 x.prop_8.prop_8 @@ -113,7 +113,7 @@ fun case_7(x: Class) { * ISSUES: KT-30376 */ fun case_8(x: Class) { - if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) { + if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) { x x.prop_8 x.prop_8.prop_8 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.fir.kt index 0444125e669..b3077d4ff86 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.fir.kt @@ -137,7 +137,7 @@ fun case_10(x: Any?, z: Any, b: Boolean?) { // TESTCASE NUMBER: 11 fun case_11(x: Any?, z: Any, b: Boolean?) { while (true) { - var y = x ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class + var y = x ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class z !== y && if (b == true) return else if (b === false) null!!else throw Exception() x y @@ -148,7 +148,7 @@ fun case_11(x: Any?, z: Any, b: Boolean?) { // TESTCASE NUMBER: 12 fun case_12(x: Any?, z: Any, b: Boolean?) { while (true) { - var y = select(x) ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class + var y = select(x) ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class select(z) !== y && if (b == true) return else if (b === false) null!!else throw Exception() x y diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt index 244235a5b1a..4485b16169c 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt @@ -31,7 +31,7 @@ fun case_3(x: ClassWithThreeTypeParameters<*, *, *>) { & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x.x x.y x.z - & ClassWithThreeTypeParameters<*, *, *>")!>x!!.ip2test() + & ClassWithThreeTypeParameters<*, *, *>")!>x!!.ip2test() & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x.x } @@ -45,7 +45,7 @@ fun case_4(x: ClassWithSixTypeParameters<*, *, *, *, *, *>?) { x.y x.z x.u - & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x!!.ip2test() + & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x!!.ip2test() ? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x ? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x.x } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt index 15de9326010..30338a08970 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt @@ -60,7 +60,7 @@ fun case_6(x: Any?) { // TESTCASE NUMBER: 7 fun case_7(x: Boolean?) { - if (x != null && x!!) { + if (x != null && x!!) { x.not() select(x).not() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/51.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/51.fir.kt index f896873e262..87e8c84541f 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/51.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/51.fir.kt @@ -263,7 +263,7 @@ fun case_22(z: Any?) { fun case_23(z: Any?) { val y = z.run { when (this) { - true -> this!! + true -> this!! 0.0 -> this as Any else -> this!! } @@ -276,7 +276,7 @@ fun case_23(z: Any?) { fun case_24(z: Any?) { val y = z.let { when (it) { - true -> it!! + true -> it!! 0.0 -> it as Any else -> it!! } @@ -292,7 +292,7 @@ fun case_25(z: Any?) { true -> this if (true) this as Int else this as Float -> this return@run this as Float -> this - else -> this!! + else -> this!! } } y @@ -306,7 +306,7 @@ fun case_26(z: Any?) { true -> it if (true) it as Int else it as Float -> it return@let it as Int -> it - else -> it!! + else -> it!! } } y diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/55.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/55.fir.kt index 00304fc6200..bfc7f45e5b0 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/55.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/55.fir.kt @@ -8,7 +8,7 @@ */ fun case_1(x: Any) { if (x is String) { - x!!.length + x!!.length x } } @@ -30,7 +30,7 @@ fun case_2(x: Any?) { */ fun case_3(x: Any) { if (x is Map.Entry<*, *>) { - ")!>x!!.key + ")!>x!!.key ")!>x } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt index f0885dadbdd..9a735e8d67e 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt @@ -35,7 +35,7 @@ fun case_4(x: Any?) { // TESTCASE NUMBER: 5 fun case_5(x: Class) { - if (x!!.prop_8 != null) { + if (x!!.prop_8 != null) { x x.prop_8.prop_8 } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index a86563d47e1..14701db72d5 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -1535,6 +1535,25 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.UNNECESSARY_NOT_NULL_ASSERTION) { firDiagnostic -> + UnnecessaryNotNullAssertionImpl( + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a), + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } + add(FirErrors.NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION) { firDiagnostic -> + NotNullAssertionOnLambdaExpressionImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } + add(FirErrors.NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE) { firDiagnostic -> + NotNullAssertionOnCallableReferenceImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.NO_ELSE_IN_WHEN) { firDiagnostic -> NoElseInWhenImpl( firDiagnostic.a.map { whenMissingCase -> diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index bac1fced1d4..44210adea3e 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1087,6 +1087,19 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val rhs: KtExpression } + abstract class UnnecessaryNotNullAssertion : KtFirDiagnostic() { + override val diagnosticClass get() = UnnecessaryNotNullAssertion::class + abstract val receiverType: KtType + } + + abstract class NotNullAssertionOnLambdaExpression : KtFirDiagnostic() { + override val diagnosticClass get() = NotNullAssertionOnLambdaExpression::class + } + + abstract class NotNullAssertionOnCallableReference : KtFirDiagnostic() { + override val diagnosticClass get() = NotNullAssertionOnCallableReference::class + } + abstract class NoElseInWhen : KtFirDiagnostic() { override val diagnosticClass get() = NoElseInWhen::class abstract val missingWhenCases: List diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index ccebe1c4dd1..ba6f91d193b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -1754,6 +1754,28 @@ internal class UnsafeOperatorCallImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class UnnecessaryNotNullAssertionImpl( + override val receiverType: KtType, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.UnnecessaryNotNullAssertion(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + +internal class NotNullAssertionOnLambdaExpressionImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.NotNullAssertionOnLambdaExpression(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + +internal class NotNullAssertionOnCallableReferenceImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.NotNullAssertionOnCallableReference(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class NoElseInWhenImpl( override val missingWhenCases: List, firDiagnostic: FirPsiDiagnostic<*>,