From 43533659689d027dc4a492251932cfcc36cce2b9 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Tue, 13 Apr 2021 20:17:48 +0300 Subject: [PATCH] [FIR] Implement NULL_FOR_NONNULL_TYPE diagnostics, fix tests --- .../testData/resolve/kt41984.kt | 2 +- .../diagnostics/FirDiagnosticsList.kt | 4 ++- .../fir/analysis/diagnostics/FirErrors.kt | 1 + .../FirInitializerTypeMismatchChecker.kt | 8 ++++- .../FirAssignmentTypeMismatchChecker.kt | 29 +++++++++++++++ .../FirFunctionReturnTypeMismatchChecker.kt | 12 ++++--- .../coneDiagnosticToFirDiagnostic.kt | 3 ++ .../fir/checkers/CommonExpressionCheckers.kt | 5 +-- .../kotlin/fir/resolve/calls/Arguments.kt | 5 ++- .../fir/resolve/calls/ResolutionDiagnostic.kt | 4 +++ .../kotlin/fir/types/FirTypeUtils.kt | 3 ++ .../tests/FunctionReturnTypes.fir.kt | 2 +- .../genericFunctionsWithNullableTypes.fir.kt | 4 +-- .../tests/controlStructures/kt10717.fir.kt | 2 +- .../approximation.fir.kt | 2 +- .../explicitDefinitelyNotNull/simple.fir.kt | 2 +- .../properties.fir.kt | 19 ---------- .../multipleBoundsMemberScope/properties.kt | 1 + .../generics/nullability/nullToGeneric.fir.kt | 35 ------------------- .../generics/nullability/nullToGeneric.kt | 1 + .../setterProjectedOutAssign.fir.kt | 2 +- .../tests/inference/regressions/kt2838.fir.kt | 2 +- ...ntsNullability-NotNull-SpecialTypes.fir.kt | 23 ------------ ...gumentsNullability-NotNull-SpecialTypes.kt | 1 + ...umentsNullability-NotNull-UserTypes.fir.kt | 23 ------------ ...eArgumentsNullability-NotNull-UserTypes.kt | 1 + .../primitiveOverrides/specializedMap.fir.kt | 2 +- .../tests/j+k/wrongVarianceInJava.fir.kt | 2 +- .../tests/platformTypes/methodCall/int.fir.kt | 16 --------- .../tests/platformTypes/methodCall/int.kt | 1 + .../noInheritanceValueParameter.fir.kt | 26 -------------- .../noInheritanceValueParameter.kt | 1 + .../substitutionInSuperType.fir.kt | 6 ++-- .../rawTypes/typeEnhancement.fir.kt | 4 +-- .../intersectionScope/properties.fir.kt | 2 +- .../javaProperties/KotlinOverridesJava.fir.kt | 4 +-- .../ParameterTypeAnnotation.fir.kt | 13 ------- .../samAdapters/ParameterTypeAnnotation.kt | 1 + .../forEachRemainingNullability.fir.kt | 2 +- .../targetedBuiltIns/mutableMapRemove.fir.kt | 2 +- ...asConstructorTypeArgumentsInference.fir.kt | 2 +- .../typeAliasObjectWithInvoke.fir.kt | 24 ------------- .../typealias/typeAliasObjectWithInvoke.kt | 1 + .../testsWithStdLib/coroutines/kt37309.fir.kt | 24 ------------- .../testsWithStdLib/coroutines/kt37309.kt | 1 + .../testsWithStdLib/regression/kt2082.fir.kt | 2 +- .../introduction-1/p-6/neg/2.1.fir.kt | 16 ++++----- .../introduction-1/p-6/neg/2.2.fir.kt | 8 ++--- .../contractBuilder/common/neg/4.fir.kt | 2 +- .../diagnostics/KtFirDataClassConverters.kt | 6 ++++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 4 +++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 7 ++++ .../checker/FunctionReturnTypes.fir.kt | 2 +- .../checker/NullAsAnnotationArgument.fir.kt | 4 +-- 54 files changed, 130 insertions(+), 251 deletions(-) create mode 100644 compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt delete mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/kt41984.kt b/compiler/fir/analysis-tests/testData/resolve/kt41984.kt index 51825da4bfa..740bc2bdeb1 100644 --- a/compiler/fir/analysis-tests/testData/resolve/kt41984.kt +++ b/compiler/fir/analysis-tests/testData/resolve/kt41984.kt @@ -26,6 +26,6 @@ open class B : A() { fun test_1(b: B, x: Int, inv: Inv) { b.take(x) - b.take(null) + b.take(null) b.takeInv(inv) } 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 a6c46210e19..5aa079436f4 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 @@ -222,6 +222,8 @@ object DIAGNOSTICS_LIST : DiagnosticList() { parameter("actualType") } + val NULL_FOR_NONNULL_TYPE by error { } + val INAPPLICABLE_LATEINIT_MODIFIER by error(PositioningStrategy.LATEINIT_MODIFIER) { parameter("reason") } @@ -336,7 +338,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() { val DEPRECATED_TYPE_PARAMETER_SYNTAX by error() val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning() - + val DYNAMIC_UPPER_BOUND by error() } 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 6a900842e11..f2e039c4e7e 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 @@ -193,6 +193,7 @@ object FirErrors { val NONE_APPLICABLE by error1>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val INAPPLICABLE_CANDIDATE by error1>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val ARGUMENT_TYPE_MISMATCH by error2() + val NULL_FOR_NONNULL_TYPE by error0() val INAPPLICABLE_LATEINIT_MODIFIER by error1(SourceElementPositioningStrategies.LATEINIT_MODIFIER) val VARARG_OUTSIDE_PARENTHESES by error0() val NAMED_ARGUMENTS_NOT_ALLOWED by error1(SourceElementPositioningStrategies.NAME_OF_NAMED_ARGUMENT) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt index 0622b90562d..d3126727c17 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt @@ -11,7 +11,9 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.isComponentCall import org.jetbrains.kotlin.fir.analysis.checkers.isSubtypeForTypeMismatch import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INITIALIZER_TYPE_MISMATCH +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.typeContext @@ -43,7 +45,11 @@ object FirInitializerTypeMismatchChecker : FirPropertyChecker() { // TODO: remove after fix of KT-45989 return } - reporter.report(INITIALIZER_TYPE_MISMATCH.on(source, propertyType, expressionType), context) + if (initializer.isNullLiteral && propertyType.nullability == ConeNullability.NOT_NULL) { + reporter.reportOn(initializer.source, FirErrors.NULL_FOR_NONNULL_TYPE, context) + } else { + reporter.report(INITIALIZER_TYPE_MISMATCH.on(source, propertyType, expressionType), context) + } } } } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt new file mode 100644 index 00000000000..e930c22fd0b --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt @@ -0,0 +1,29 @@ +/* + * 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.expressions.FirVariableAssignment +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol +import org.jetbrains.kotlin.fir.types.ConeNullability +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.isNullLiteral + +object FirAssignmentTypeMismatchChecker : FirVariableAssignmentChecker() { + override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) { + val rValue = expression.rValue + if (rValue.isNullLiteral) { + val leftType = ((expression.lValue as? FirResolvedNamedReference)?.resolvedSymbol as? FirPropertySymbol)?.fir?.returnTypeRef + if (leftType?.coneType?.nullability == ConeNullability.NOT_NULL) { + reporter.reportOn(rValue.source, FirErrors.NULL_FOR_NONNULL_TYPE, context) + } + } + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt index c69afc2b669..0ead64d87e5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt @@ -8,15 +8,15 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.isSubtypeForTypeMismatch import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NULL_FOR_NONNULL_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_TYPE_MISMATCH +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.expressions.FirReturnExpression import org.jetbrains.kotlin.fir.expressions.FirWhenExpression import org.jetbrains.kotlin.fir.expressions.isExhaustive import org.jetbrains.kotlin.fir.typeContext -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.coneType -import org.jetbrains.kotlin.fir.types.coneTypeSafe +import org.jetbrains.kotlin.fir.types.* object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() { override fun check(expression: FirReturnExpression, context: CheckerContext, reporter: DiagnosticReporter) { @@ -33,7 +33,11 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() { if (!isSubtypeForTypeMismatch(typeContext, subtype = returnExpressionType, supertype = functionReturnType)) { val returnExpressionSource = resultExpression.source ?: return - reporter.report(RETURN_TYPE_MISMATCH.on(returnExpressionSource, functionReturnType, returnExpressionType), context) + if (resultExpression.isNullLiteral && functionReturnType.nullability == ConeNullability.NOT_NULL) { + reporter.reportOn(resultExpression.source, NULL_FOR_NONNULL_TYPE, context) + } else { + reporter.report(RETURN_TYPE_MISMATCH.on(returnExpressionSource, functionReturnType, returnExpressionType), context) + } } } } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index f3bff40b098..12e555dba29 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -142,6 +142,9 @@ private fun mapInapplicableCandidateError( rootCause.expectedType, rootCause.actualType ) + is NullForNotNullType -> FirErrors.NULL_FOR_NONNULL_TYPE.on( + rootCause.argument.source ?: source + ) is NonVarargSpread -> FirErrors.NON_VARARG_SPREAD.on(rootCause.argument.source?.getChild(KtTokens.MUL, depth = 1)!!) is ArgumentPassedTwice -> FirErrors.ARGUMENT_PASSED_TWICE.on(rootCause.argument.source) is TooManyArguments -> FirErrors.TOO_MANY_ARGUMENTS.on(rootCause.argument.source ?: source, rootCause.function) 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 cdec8c8847a..654ec4921eb 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 @@ -30,7 +30,7 @@ object CommonExpressionCheckers : ExpressionCheckers() { FirTypeParameterInQualifiedAccessChecker, FirSealedClassConstructorCallChecker, FirUninitializedEnumChecker, - FirFunInterfaceConstructorReferenceChecker, + FirFunInterfaceConstructorReferenceChecker, ) override val functionCallCheckers: Set @@ -46,7 +46,8 @@ object CommonExpressionCheckers : ExpressionCheckers() { override val variableAssignmentCheckers: Set get() = setOf( - FirValReassignmentViaBackingFieldChecker + FirValReassignmentViaBackingFieldChecker, + FirAssignmentTypeMismatchChecker ) override val whenExpressionCheckers: Set diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index b1cebae3e80..ecfb7d5616a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -353,6 +353,10 @@ private fun checkApplicabilityForArgumentType( } } + if (argument.isNullLiteral && actualExpectedType.nullability == ConeNullability.NOT_NULL) { + return NullForNotNullType(argument) + } + fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType { if (type is ConeTypeVariableType) { val originalTypeParameter = @@ -374,7 +378,6 @@ private fun checkApplicabilityForArgumentType( ) } - if (isReceiver && isDispatch) { if (!expectedType.isNullable && argumentType.isMarkedNullable) { sink.reportDiagnostic(InapplicableWrongReceiver(expectedType, argumentType)) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt index 274598ee84f..000446bee01 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt @@ -92,3 +92,7 @@ class ArgumentTypeMismatch( val actualType: ConeKotlinType, val argument: FirExpression ) : ResolutionDiagnostic(INAPPLICABLE) + +class NullForNotNullType( + val argument: FirExpression +) : ResolutionDiagnostic(INAPPLICABLE) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt index 448c862302e..11564545ba9 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.fir.types import org.jetbrains.kotlin.builtins.functions.FunctionClassKind import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirConstExpression +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.name.StandardClassIds @@ -41,6 +43,7 @@ val FirTypeRef.isArrayType: Boolean get() = isBuiltinType(StandardClassIds.Array, false) || StandardClassIds.primitiveArrayTypeByElementType.values.any { isBuiltinType(it, false) } +val FirExpression.isNullLiteral: Boolean get() = this is FirConstExpression<*> && this.value == null && this.source != null private val FirTypeRef.classLikeTypeOrNull: ConeClassLikeType? get() = when (this) { diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt index f93d087d8af..73ce3f42863 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt @@ -30,7 +30,7 @@ fun foo(expr: StringBuilder): Int { fun unitShort() : Unit = Unit fun unitShortConv() : Unit = 1 -fun unitShortNull() : Unit = null +fun unitShortNull() : Unit = null fun intEmpty() : Int {} fun intShortInfer() = 1 diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt index 6ec37379837..4cb176ad67a 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt @@ -23,8 +23,8 @@ fun test(x: T) { baz(null, null, ::foo) - baz(null, null, ::foo) - baz(null, null, ::foo) + baz(null, null, ::foo) + baz(null, null, ::foo) baz(null, "", ::foo) baz(1, null, ::foo) baz(null, null, ::foo) diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt index ad95a36e687..17d7e65b2ba 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt @@ -13,7 +13,7 @@ fun test2() = run { inline fun Iterable.map(transform: (T) -> R): List = null!! fun test3(a: List, b: List) = a.map { - if (it.length == 3) return null + if (it.length == 3) return null if (it.length == 4) return "" if (it.length == 4) return 5 if (it.length == 4) return b diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.fir.kt index 77f22f30f25..e4d28e010fe 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.fir.kt @@ -4,7 +4,7 @@ fun foo(x: T, y: T!!) = x!! fun main() { foo("", "").length - foo("", null).length + foo("", null).length foo(null, "").length foo(null, null).length diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/simple.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/simple.fir.kt index 8bf5d49104b..b5e2360fbfc 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/simple.fir.kt @@ -4,7 +4,7 @@ fun foo(x: T, y: T!!): T!! = x ?: y fun main() { foo("", "").length - foo("", null).length + foo("", null).length foo(null, "").length foo(null, null).length diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt deleted file mode 100644 index d9160c9c5cf..00000000000 --- a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -// !CHECK_TYPE - -interface A { - val foo: Any? -} - -interface C: A { - override val foo: String? -} -interface B: A { - override var foo: String -} - -fun test(a: T) where T : B, T : C { - a.foo = "" - a.foo = null - - a.foo.checkType { _() } -} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.kt index 6f548bd7aa5..ceb4e756c07 100644 --- a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.kt +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE interface A { diff --git a/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt deleted file mode 100644 index 2eb58cc71eb..00000000000 --- a/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt +++ /dev/null @@ -1,35 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE - -fun bar(x: E) {} - -fun foo(): T { - val x1: T = null - val x2: T? = null - - bar(null) - bar(null) - - return null -} - -fun baz(): T? = null - -fun foobar(): T = null - -class A { - fun xyz(x: F) {} - - fun foo(): F { - val x1: F = null - val x2: F? = null - - xyz(null) - bar(null) - - return null - } - - fun baz(): F? = null - - fun foobar(): F = null -} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt b/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt index b6be648e521..518f249da69 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE fun bar(x: E) {} diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt index 6812fed723e..6e586fd7c04 100644 --- a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt @@ -9,6 +9,6 @@ interface Tr { fun test(t: Tr<*>) { t.v = null!! t.v = "" - t.v = null + t.v = null t.v checkType { _() } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt index 251bcd5cc03..7430a30235d 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt @@ -8,7 +8,7 @@ fun bar(a: T, b: Map) = b.get(a) fun test(a: Int) { foo(a, null) - bar(a, null) + bar(a, null) } fun test1(a: Int) { foo(a, throw Exception()) diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt deleted file mode 100644 index 244b83e407f..00000000000 --- a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// !CHECK_TYPE -// FILE: A.java -public class A {} - -// FILE: X.java -import org.jetbrains.annotations.NotNull; - -public class X { - @NotNull T fooN() {return null;} - void barN(@NotNull T a) {} -} - -// FILE: Y.java -public class Y extends X { - -} - -// FILE: test.kt - -fun main() { - checkSubtype(Y().fooN()) - Y().barN(null); -} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.kt index 52fc47305f0..349b51c04b3 100644 --- a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.kt +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE // FILE: A.java public class A {} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt deleted file mode 100644 index 549c3e7e7eb..00000000000 --- a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// !CHECK_TYPE -// FILE: A.java -public class A {} - -// FILE: X.java -import org.jetbrains.annotations.NotNull; - -public class X { - @NotNull T fooN() {return null;} - void barN(@NotNull T a) {} -} - -// FILE: Y.java -public class Y extends X { - -} - -// FILE: test.kt - -fun main() { - checkSubtype(Y().fooN()) - Y().barN(null); -} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.kt index 2dc98dd7583..d497444035c 100644 --- a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.kt +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE // FILE: A.java public class A {} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt index e6b82938b98..2600623f44e 100644 --- a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt @@ -100,7 +100,7 @@ public class SpecializedMap extends AbstractSpecializedMap { // FILE: main.kt fun foo(x: SpecializedMap) { x.containsKey(1) - x.containsKey(null) + x.containsKey(null) x.get(2) x.get(null) diff --git a/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt index 0995db885ab..992af681e14 100644 --- a/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt @@ -20,5 +20,5 @@ class In { fun test() { A.foo().x() checkType { _() } - A.bar().y(null) + A.bar().y(null) } diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt deleted file mode 100644 index 9c94624f2d9..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt +++ /dev/null @@ -1,16 +0,0 @@ -// FILE: p/J.java - -package p; - -public class J { - public void _int(int s) {} -} - -// FILE: k.kt - -import p.* - -fun test() { - J()._int(1) - J()._int(null) -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.kt index 091da1de6db..936d80ebcd7 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: p/J.java package p; diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt deleted file mode 100644 index 837df1f1c86..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt +++ /dev/null @@ -1,26 +0,0 @@ -// FILE: A.java - -import java.util.*; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class A { - public static A create() { - return null; - } - - public void bar(@NotNull T x) { - } -} - -// FILE: k.kt - -fun test() { - A.create().bar(null) - A.create().bar("") - - A().bar(null) - A().bar(null) - A().bar("") -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.kt index dd8a96e1d1c..24ce9821a5c 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java import java.util.*; diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt index 9589725a8a9..70550717f38 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt @@ -33,9 +33,9 @@ class C2 : A() { } fun test() { - B1().bar(null) - B2().bar(null) + B1().bar(null) + B2().bar(null) - C1().bar(null) + C1().bar(null) } diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt index 01a463b476a..966faf46cfb 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt @@ -22,6 +22,6 @@ val doubleList: List = null!! fun main() { Test.rawField.foo("", doubleList) - Test.rawField.foo(null, doubleList) - Test.DerivedRawA().foo(null, doubleList) + Test.rawField.foo(null, doubleList) + Test.DerivedRawA().foo(null, doubleList) } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt index 49a679504c8..0481364fa78 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt @@ -14,7 +14,7 @@ interface B: A { fun test(a: A) { if (a is B && a is C) { a.foo = "" - a.foo = null + a.foo = null a.foo.checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt index b4fa44d5245..96fb042fcda 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt @@ -23,8 +23,8 @@ fun foo(k: KotlinClass) { k.setSomething4("") k.something4 += "" - k.setSomething4(null) - k.something4 = null + k.setSomething4(null) + k.something4 = null useString(k.getSomething5()) useString(k.something5) diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt deleted file mode 100644 index f7bdb35c13a..00000000000 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -// !WITH_NEW_INFERENCE -// FILE: KotlinFile.kt -fun foo(javaInterface: JavaInterface) { - javaInterface.doIt(null) { } - javaInterface.doIt("", null) -} - -// FILE: JavaInterface.java -import org.jetbrains.annotations.*; - -public interface JavaInterface { - void doIt(@NotNull String s, @NotNull Runnable runnable); -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.kt index 1bfca31f3ea..a5080f928f4 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !WITH_NEW_INFERENCE // FILE: KotlinFile.kt fun foo(javaInterface: JavaInterface) { diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt index 63d48ffc6f3..d456941ce4b 100644 --- a/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt @@ -32,7 +32,7 @@ abstract class MyIt7 : Iterator { fun foo(x: Iterator, y: Iterator) { - x.forEachRemaining(null) + x.forEachRemaining(null) x.forEachRemaining { it -> it.length } x.forEachRemaining { it -> it?.length } diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt index 001df3f2519..486557a4fce 100644 --- a/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt @@ -19,7 +19,7 @@ class KotlinMap2 : java.util.AbstractMap() { fun foo(x: MutableMap, y: java.util.HashMap, z: java.util.AbstractMap) { x.remove("", 1) x.remove("", "") - x.remove("", null) + x.remove("", null) y.remove("", 1) y.remove("", "") diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt index 7a88b7d993a..66d0fdbedec 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt @@ -21,7 +21,7 @@ class Pair(val x: X, val y: Y) typealias PL = Pair> typealias PN = Pair> -val test5 = PL(1, null) +val test5 = PL(1, null) class Foo(val p: Pair) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt deleted file mode 100644 index 79972549f79..00000000000 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt +++ /dev/null @@ -1,24 +0,0 @@ -// !WITH_NEW_INFERENCE -// NI_EXPECTED_FILE - -object ObjectWithInvoke { - operator fun invoke() = this -} - -class ClassWithCompanionObjectWithInvoke { - companion object { - operator fun invoke(x: Any) = x - } -} - -typealias WI = ObjectWithInvoke - -typealias CWI = ClassWithCompanionObjectWithInvoke - -val test1 = WI() -val test2 = WI(null) - -val test3 = CWI() -val test4 = CWI("") -val test5 = CWI(null) -val test5a = ClassWithCompanionObjectWithInvoke(null) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt index 51940a6ec13..96b227857fc 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !WITH_NEW_INFERENCE // NI_EXPECTED_FILE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt deleted file mode 100644 index 67afccd697d..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt +++ /dev/null @@ -1,24 +0,0 @@ -// !USE_EXPERIMENTAL: kotlin.RequiresOptIn -// !DIAGNOSTICS: -UNUSED_VARIABLE - -import kotlin.experimental.ExperimentalTypeInference - -@OptIn(ExperimentalTypeInference::class) -fun myBuildList(@BuilderInference builderAction: MutableList.() -> Unit) { - ArrayList().builderAction() -} - -@OptIn(ExperimentalStdlibApi::class) -fun main() { - val newList1 = myBuildList { - addAll( - listOf(1).map { Foo(null) } - ) - } - - val newList2 = buildList { - addAll(listOf(1,2,3).map{ Foo(null) }) - } -} - -class Foo(val notNullProp: String) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.kt index f931c6132de..dd5f589d8aa 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt index bbd01a4f89b..0e7b883fc77 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt @@ -7,4 +7,4 @@ fun foo(c : Collection) = { } fun bar() : String? = null -fun zoo(s : String) : Boolean = true \ No newline at end of file +fun zoo(s : String) : Boolean = true diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.1.fir.kt index 77015dfce02..f47ecdce07c 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.1.fir.kt @@ -4,44 +4,44 @@ // TESTCASE NUMBER: 1 fun case_1() { - val x: Int = null + val x: Int = null } // TESTCASE NUMBER: 2 fun case_2() { - val x: Any = null + val x: Any = null } // TESTCASE NUMBER: 3 fun case_3() { - val x: Nothing = null + val x: Nothing = null } // TESTCASE NUMBER: 4 fun case_4() { - var x: Int = null + var x: Int = null } // TESTCASE NUMBER: 5 fun case_5() { - var x: Any = null + var x: Any = null } // TESTCASE NUMBER: 6 fun case_6() { - var x: Nothing = null + var x: Nothing = null } // TESTCASE NUMBER: 7 fun case_7() { val x: Int - x = null + x = null } // TESTCASE NUMBER: 8 fun case_8() { var x: Int = 10 - x = null + x = null } // TESTCASE NUMBER: 9 diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt index ca21cdde700..b5b7b27a885 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt @@ -43,7 +43,7 @@ class Case8 { } // TESTCASE NUMBER: 9 -fun case_9(): Any = null +fun case_9(): Any = null // TESTCASE NUMBER: 10 fun case_10(x: Int, y: Boolean): Any = if (y) x else null @@ -57,10 +57,10 @@ class Case12 { var y: Any var z: Any init { - x = null - y = null + x = null + y = null z = 10 - z = null + z = null } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.fir.kt index 55e406b51b6..8136cb2eff9 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.fir.kt @@ -6,7 +6,7 @@ import kotlin.contracts.* // TESTCASE NUMBER: 1 fun case_1(): Boolean? { - contract { returnsNotNull() implies (null) } + contract { returnsNotNull() implies (null) } return true } 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 8b71e08e929..2084245db3c 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 @@ -739,6 +739,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.NULL_FOR_NONNULL_TYPE) { firDiagnostic -> + NullForNonnullTypeImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.INAPPLICABLE_LATEINIT_MODIFIER) { firDiagnostic -> InapplicableLateinitModifierImpl( firDiagnostic.a, 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 2c4587defe9..898af03a93a 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 @@ -532,6 +532,10 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val actualType: KtType } + abstract class NullForNonnullType : KtFirDiagnostic() { + override val diagnosticClass get() = NullForNonnullType::class + } + abstract class InapplicableLateinitModifier : KtFirDiagnostic() { override val diagnosticClass get() = InapplicableLateinitModifier::class abstract val reason: String 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 fc81f8051d2..66278e9b576 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 @@ -851,6 +851,13 @@ internal class ArgumentTypeMismatchImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class NullForNonnullTypeImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.NullForNonnullType(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class InapplicableLateinitModifierImpl( override val reason: String, firDiagnostic: FirPsiDiagnostic<*>, diff --git a/idea/testData/checker/FunctionReturnTypes.fir.kt b/idea/testData/checker/FunctionReturnTypes.fir.kt index ab4aa1f6db5..418c0adc01f 100644 --- a/idea/testData/checker/FunctionReturnTypes.fir.kt +++ b/idea/testData/checker/FunctionReturnTypes.fir.kt @@ -27,7 +27,7 @@ fun foo(expr: StringBuilder): Int { fun unitShort() : Unit = Unit fun unitShortConv() : Unit = 1 -fun unitShortNull() : Unit = null +fun unitShortNull() : Unit = null fun intEmpty() : Int {} fun intShortInfer() = 1 diff --git a/idea/testData/checker/NullAsAnnotationArgument.fir.kt b/idea/testData/checker/NullAsAnnotationArgument.fir.kt index d9b53396379..8d245dfcf67 100644 --- a/idea/testData/checker/NullAsAnnotationArgument.fir.kt +++ b/idea/testData/checker/NullAsAnnotationArgument.fir.kt @@ -3,8 +3,8 @@ package test annotation class A(val value: String) -@A(null) +@A(null) fun foo() {} -@A(null) +@A(null) class B