diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot index bc7ce6fce2e..56fc7892772 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot @@ -702,44 +702,45 @@ digraph boundSmartcastsInBranches_kt { 293 [label="Access variable R|/x|"]; 294 [label="Access variable #"]; 295 [label="Access variable R|/y|"]; - 296 [label="Access variable R|kotlin/String.length|"]; - 297 [label="Access variable R|/z|"]; - 298 [label="Access variable #"]; - 299 [label="Exit block"]; + 296 [label="Stub" style="filled" fillcolor=gray]; + 297 [label="Access variable R|kotlin/String.length|" style="filled" fillcolor=gray]; + 298 [label="Access variable R|/z|" style="filled" fillcolor=gray]; + 299 [label="Access variable #" style="filled" fillcolor=gray]; + 300 [label="Exit block" style="filled" fillcolor=gray]; } - 300 [label="Exit when branch result"]; - 301 [label="Exit when"]; + 301 [label="Exit when branch result" style="filled" fillcolor=gray]; + 302 [label="Exit when"]; } subgraph cluster_67 { color=blue - 302 [label="Enter when"]; + 303 [label="Enter when"]; subgraph cluster_68 { color=blue - 303 [label="Enter when branch condition "]; - 304 [label="Access variable R|/z|"]; - 305 [label="Const: Null(null)"]; - 306 [label="Equality operator !="]; - 307 [label="Exit when branch condition"]; + 304 [label="Enter when branch condition "]; + 305 [label="Access variable R|/z|"]; + 306 [label="Const: Null(null)"]; + 307 [label="Equality operator !="]; + 308 [label="Exit when branch condition"]; } - 308 [label="Synthetic else branch"]; - 309 [label="Enter when branch result"]; + 309 [label="Synthetic else branch"]; + 310 [label="Enter when branch result"]; subgraph cluster_69 { color=blue - 310 [label="Enter block"]; - 311 [label="Access variable R|/x|"]; - 312 [label="Access variable R|kotlin/String.length|"]; - 313 [label="Access variable R|/y|"]; - 314 [label="Access variable #"]; - 315 [label="Access variable R|/z|"]; - 316 [label="Access variable R|kotlin/String.length|"]; - 317 [label="Exit block"]; + 311 [label="Enter block"]; + 312 [label="Access variable R|/x|"]; + 313 [label="Access variable R|kotlin/String.length|"]; + 314 [label="Access variable R|/y|"]; + 315 [label="Access variable #"]; + 316 [label="Access variable R|/z|"]; + 317 [label="Access variable R|kotlin/String.length|"]; + 318 [label="Exit block"]; } - 318 [label="Exit when branch result"]; - 319 [label="Exit when"]; + 319 [label="Exit when branch result"]; + 320 [label="Exit when"]; } - 320 [label="Exit block"]; + 321 [label="Exit block"]; } - 321 [label="Exit function test_7" style="filled" fillcolor=red]; + 322 [label="Exit function test_7" style="filled" fillcolor=red]; } 202 -> {203}; 203 -> {204}; @@ -829,26 +830,27 @@ digraph boundSmartcastsInBranches_kt { 287 -> {288}; 288 -> {289}; 289 -> {291 290}; - 290 -> {301}; + 290 -> {302}; 291 -> {292}; 292 -> {293}; 293 -> {294}; 294 -> {295}; - 295 -> {296}; - 296 -> {297}; - 297 -> {298}; - 298 -> {299}; - 299 -> {300}; - 300 -> {301}; - 301 -> {302}; + 295 -> {322} [label=onUncaughtException]; + 295 -> {296} [style=dotted]; + 296 -> {297} [style=dotted]; + 297 -> {298} [style=dotted]; + 298 -> {299} [style=dotted]; + 299 -> {300} [style=dotted]; + 300 -> {301} [style=dotted]; + 301 -> {302} [style=dotted]; 302 -> {303}; 303 -> {304}; 304 -> {305}; 305 -> {306}; 306 -> {307}; - 307 -> {309 308}; - 308 -> {319}; - 309 -> {310}; + 307 -> {308}; + 308 -> {310 309}; + 309 -> {320}; 310 -> {311}; 311 -> {312}; 312 -> {313}; @@ -860,5 +862,6 @@ digraph boundSmartcastsInBranches_kt { 318 -> {319}; 319 -> {320}; 320 -> {321}; + 321 -> {322}; } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 296b75c501a..edde64654f3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -32,10 +32,10 @@ import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.transformers.firClassLike -import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData import org.jetbrains.kotlin.fir.scopes.impl.importedFromObjectData import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef @@ -266,10 +266,21 @@ fun BodyResolveComponents.transformQualifiedAccessUsingSmartcastInfo( } else { SmartcastStability.STABLE_VALUE } + val originalType = qualifiedAccessExpression.resultType.coneType + val allTypes = typesFromSmartCast.also { + it += originalType + } + val intersectedType = ConeTypeIntersector.intersectTypes(session.inferenceComponents.ctx, allTypes) + if (intersectedType == originalType) return qualifiedAccessExpression + val intersectedTypeRef = buildResolvedTypeRef { + source = qualifiedAccessExpression.resultType.source?.fakeElement(FirFakeSourceElementKind.SmartCastedTypeRef) + type = intersectedType + annotations += qualifiedAccessExpression.resultType.annotations + delegatedTypeRef = qualifiedAccessExpression.resultType + } // For example, if (x == null) { ... }, - // we don't want to smartcast to Nothing?, but we want to record the nullability to its own kind of node. - // TODO: should we differentiate x == null v.s. x is Nothing? + // we need to track the type without `Nothing?` so that resolution with this as receiver can go through properly. if (typesFromSmartCast.any { it.isNullableNothing }) { val typesFromSmartcastWithoutNullableNothing = typesFromSmartCast.filterTo(mutableListOf()) { !it.isNullableNothing }.also { @@ -285,24 +296,13 @@ fun BodyResolveComponents.transformQualifiedAccessUsingSmartcastInfo( } return buildExpressionWithSmartcastToNull { originalExpression = qualifiedAccessExpression - // TODO: Use Nothing? during resolution? - smartcastType = intersectedTypeRefWithoutNullableNothing - // NB: Nothing? in types from smartcast in DFA is recorded here (and the expression kind itself). + smartcastType = intersectedTypeRef + smartcastTypeWithoutNullableNothing = intersectedTypeRefWithoutNullableNothing this.typesFromSmartCast = typesFromSmartCast this.smartcastStability = smartcastStability } } - val allTypes = typesFromSmartCast.also { - it += originalType - } - val intersectedType = ConeTypeIntersector.intersectTypes(session.inferenceComponents.ctx, allTypes) - if (intersectedType == originalType) return qualifiedAccessExpression - val intersectedTypeRef = buildResolvedTypeRef { - source = qualifiedAccessExpression.resultType.source?.fakeElement(FirFakeSourceElementKind.SmartCastedTypeRef) - type = intersectedType - annotations += qualifiedAccessExpression.resultType.annotations - delegatedTypeRef = qualifiedAccessExpression.resultType - } + return buildExpressionWithSmartcast { originalExpression = qualifiedAccessExpression smartcastType = intersectedTypeRef @@ -339,7 +339,13 @@ fun FirAnnotationCall.fqName(session: FirSession): FqName? { } fun FirCheckedSafeCallSubject.propagateTypeFromOriginalReceiver(nullableReceiverExpression: FirExpression, session: FirSession) { - val receiverType = nullableReceiverExpression.typeRef.coneTypeSafe() ?: return + // If the receiver expression is smartcast to `null`, it would have `Nothing?` as its type, which may not have members called by user + // code. Hence, we fallback to the type before intersecting with `Nothing?`. + val receiverType = ((nullableReceiverExpression as? FirExpressionWithSmartcastToNull) + ?.takeIf { it.isStable } + ?.smartcastTypeWithoutNullableNothing + ?: nullableReceiverExpression.typeRef) + .coneTypeSafe() ?: return val expandedReceiverType = if (receiverType is ConeClassLikeType) receiverType.fullyExpandedType(session) else receiverType diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index ba8f9bc5170..3a922612402 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -11,8 +11,8 @@ import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast +import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNull import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap -import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirScopeWithFakeOverrideTypeCalculat import org.jetbrains.kotlin.fir.scopes.impl.FirStandardOverrideChecker import org.jetbrains.kotlin.fir.scopes.impl.FirTypeIntersectionScope import org.jetbrains.kotlin.fir.scopes.scopeForClass +import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol @@ -33,7 +34,8 @@ fun FirExpressionWithSmartcast.smartcastScope( useSiteSession: FirSession, scopeSession: ScopeSession ): FirTypeScope? { - val smartcastType = smartcastType.coneType + val smartcastType = + if (this is FirExpressionWithSmartcastToNull) smartcastTypeWithoutNullableNothing.coneType else smartcastType.coneType val smartcastScope = smartcastType.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing) if (isStable) { return smartcastScope diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt index a1b666ff181..513a098b4f9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt @@ -7,9 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic -import org.jetbrains.kotlin.fir.expressions.FirExpression -import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast -import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast import org.jetbrains.kotlin.fir.expressions.builder.buildThisReceiverExpression import org.jetbrains.kotlin.fir.references.builder.buildImplicitThisReference @@ -60,9 +58,18 @@ abstract class AbstractExplicitReceiverValue : AbstractExplic class ExpressionReceiverValue( override val explicitReceiver: FirExpression ) : AbstractExplicitReceiverValue(), ReceiverValue { - override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = - (receiverExpression as? FirExpressionWithSmartcast)?.smartcastScope(useSiteSession, scopeSession) - ?: type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing) + override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? { + var receiverExpr: FirExpression? = receiverExpression + // Unwrap `x!!` to `x` and use the resulted expression to derive receiver type. This is necessary so that smartcast types inside + // `!!` is handled correctly. + if (receiverExpr is FirCheckNotNullCall) { + receiverExpr = receiverExpr.arguments.firstOrNull() + } + if (receiverExpr is FirExpressionWithSmartcast) { + return receiverExpr.smartcastScope(useSiteSession, scopeSession) + } + return type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing) + } } sealed class ImplicitReceiverValue>( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index 02fa1997c05..dbd3062cc73 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.FirVisibilityChecker import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isInfix @@ -23,13 +22,14 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.visibilityChecker import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.* import org.jetbrains.kotlin.types.AbstractNullabilityChecker -import org.jetbrains.kotlin.types.SmartcastStability abstract class ResolutionStage { abstract suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) @@ -116,9 +116,8 @@ object CheckDispatchReceiver : ResolutionStage() { (candidate.originScope as? FirUnstableSmartcastTypeScope)?.isSymbolFromUnstableSmartcast(candidate.symbol) == true if (explicitReceiverExpression is FirExpressionWithSmartcast && - explicitReceiverExpression !is FirExpressionWithSmartcastToNull && - explicitReceiverExpression.smartcastStability != SmartcastStability.STABLE_VALUE && - (isCandidateFromUnstableSmartcast || isReceiverNullable) + !explicitReceiverExpression.isStable && + (isCandidateFromUnstableSmartcast || (isReceiverNullable && !explicitReceiverExpression.smartcastType.canBeNull)) ) { sink.yieldDiagnostic(UnstableSmartCast(explicitReceiverExpression, explicitReceiverExpression.smartcastType.coneType)) } else if (isReceiverNullable) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index 4bcff052fff..ca8ea54ca09 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -1124,14 +1124,7 @@ abstract class FirDataFlowAnalyzer( } if (isAssignment) { - if (initializer is FirConstExpression<*> && initializer.kind == ConstantValueKind.Null) { - flow.addTypeStatement( - propertyVariable typeEq - property.returnTypeRef.coneType.withNullability(ConeNullability.NULLABLE, components.session.typeContext) - ) - } else { - flow.addTypeStatement(propertyVariable typeEq initializer.typeRef.coneType) - } + flow.addTypeStatement(propertyVariable typeEq initializer.typeRef.coneType) } } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirExpressionWithSmartcastToNull.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirExpressionWithSmartcastToNull.kt index 167280223c8..85e7d4fdcd5 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirExpressionWithSmartcastToNull.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirExpressionWithSmartcastToNull.kt @@ -36,6 +36,7 @@ abstract class FirExpressionWithSmartcastToNull : FirExpressionWithSmartcast() { abstract override val typesFromSmartCast: Collection abstract override val originalType: FirTypeRef abstract override val smartcastType: FirTypeRef + abstract val smartcastTypeWithoutNullableNothing: FirTypeRef abstract override val smartcastStability: SmartcastStability override fun accept(visitor: FirVisitor, data: D): R = visitor.visitExpressionWithSmartcastToNull(this, data) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirExpressionWithSmartcastToNullBuilder.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirExpressionWithSmartcastToNullBuilder.kt index 6cb615e68c9..c61bd7ccc33 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirExpressionWithSmartcastToNullBuilder.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirExpressionWithSmartcastToNullBuilder.kt @@ -17,9 +17,17 @@ class FirExpressionWithSmartcastToNullBuilder { lateinit var smartcastType: FirTypeRef lateinit var typesFromSmartCast: Collection lateinit var smartcastStability: SmartcastStability + lateinit var smartcastTypeWithoutNullableNothing: FirTypeRef fun build(): FirExpressionWithSmartcastToNull { - return FirExpressionWithSmartcastToNullImpl(originalExpression, smartcastType, typesFromSmartCast, smartcastStability, listOf()) + return FirExpressionWithSmartcastToNullImpl( + originalExpression, + smartcastType, + typesFromSmartCast, + smartcastStability, + smartcastTypeWithoutNullableNothing, + listOf() + ) } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionWithSmartcastToNullImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionWithSmartcastToNullImpl.kt index b1ad023319b..3530145482e 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionWithSmartcastToNullImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionWithSmartcastToNullImpl.kt @@ -27,6 +27,7 @@ class FirExpressionWithSmartcastToNullImpl( override val smartcastType: FirTypeRef, override val typesFromSmartCast: Collection, override val smartcastStability: SmartcastStability, + override val smartcastTypeWithoutNullableNothing: FirTypeRef, override val nonFatalDiagnostics: List ) : FirExpressionWithSmartcastToNull() { init { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index de123f11938..42ba83c201e 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -466,6 +466,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +field("typesFromSmartCast", "Collection", null, customType = coneKotlinTypeType) +field("originalType", typeRef) +field("smartcastType", typeRef) + +field("smartcastTypeWithoutNullableNothing", typeRef) +smartcastStability } diff --git a/compiler/testData/codegen/box/smartCasts/nullSmartCast.kt b/compiler/testData/codegen/box/smartCasts/nullSmartCast.kt index 41cd6812690..ff713cc9dbe 100644 --- a/compiler/testData/codegen/box/smartCasts/nullSmartCast.kt +++ b/compiler/testData/codegen/box/smartCasts/nullSmartCast.kt @@ -1,6 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM // WASM_MUTE_REASON: NULL_REF_CAST -// IGNORE_BACKEND_FIR: JVM_IR fun String?.foo() = this ?: "OK" fun foo(i: Int?): String { diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt index 8058722c1ae..abde368a993 100644 --- a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt @@ -5,24 +5,24 @@ class A() { fun f(): Unit { var x: Int? = 1 x = null - x + 1 + x + 1 x plus 1 x < 1 - x += 1 + x += 1 x == 1 x != 1 A() == 1 - x === "1" - x !== "1" + x === "1" + x !== "1" x === 1 x !== 1 - x..2 - x in 1..2 + x..2 + x in 1..2 val y : Boolean? = true false || y diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt index 232b824a451..23aec1820f0 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt @@ -8,7 +8,7 @@ fun foo(): Int { if (x != null) return x val y: Int? = null - if (y == null) return if (y != null) y else y + if (y == null) return if (y != null) y else y val z: Int? = null if (z != null) return if (z == null) z else z diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt index 2b772126b58..029098303c1 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt @@ -173,15 +173,15 @@ fun test() { if (get() === null) {} if (x == null) { - x?.hashCode() + x?.hashCode() } if (x == null) { - x?.equals(1) + x?.equals(1) } if (x == null) { - x?.test2() + x?.test2() } if (x == null) { @@ -189,15 +189,15 @@ fun test() { } if (x === null) { - x?.hashCode() + x?.hashCode() } if (x === null) { - x?.equals(1) + x?.equals(1) } if (x === null) { - x?.test2() + x?.test2() } if (x === null) { @@ -303,9 +303,9 @@ fun test() { if (get() === null) {} if (x == null) { - x?.hashCode() - x?.equals(1) - x?.test2() + x?.hashCode() + x?.equals(1) + x?.test2() x.test2() } diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt index b52ad579826..7e67073c110 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt @@ -7,7 +7,7 @@ fun foo(): String { var t: String? = "y" if (t == null) t = "x" var x: Int? = null - if (x == null) x += null + if (x == null) x += null return t + s } @@ -16,7 +16,7 @@ fun String?.gav() {} fun bar(s: String?) { if (s != null) return s.gav() - s as? String - s as String? + s as? String + s as String? s as String } diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt deleted file mode 100644 index f731335719b..00000000000 --- a/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt +++ /dev/null @@ -1,16 +0,0 @@ -// FILE: My.java - -public class My { - static public My create() { return new My(); } - public void foo() {} -} - -// FILE: Test.kt - -fun test() { - val my = My.create() - if (my == null) { - my.foo() - } -} - diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt index e4012d70daa..a8961244433 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: My.java public class My { diff --git a/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt index aec616263c4..79f5394c110 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt @@ -7,14 +7,14 @@ class TestWithEquals { } fun bar(i: Test?) { - if (i == null) foo(i) + if (i == null) foo(i) } fun bar(i: TestWithEquals?) { - if (i == null) foo(i) - if (null == i) foo(i) + if (i == null) foo(i) + if (null == i) foo(i) when (i) { - null -> foo(i) + null -> foo(i) } } @@ -22,4 +22,4 @@ fun gav(i: TestWithEquals?, j: TestWithEquals?) { if (j == null) { if (i == j) foo(i) } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.fir.kt index 99d461442fa..b4d7d1b0e13 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.fir.kt @@ -19,11 +19,11 @@ fun g(x: B) { val y = x.content if (y == null) { f(y) - g(y) + g(y) } if (y is Nothing?) { f(y) - g(y) + g(y) } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt index 521e424a20c..b8626eb17fa 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt @@ -1,5 +1,5 @@ fun foo(): Int { var i: Int? = 42 i = null - return i + 1 + return i + 1 } diff --git a/compiler/testData/diagnostics/tests/when/whenOnNothing.txt b/compiler/testData/diagnostics/tests/when/whenOnNothing.txt index 8fa146ec65a..d952e2fe32a 100644 --- a/compiler/testData/diagnostics/tests/when/whenOnNothing.txt +++ b/compiler/testData/diagnostics/tests/when/whenOnNothing.txt @@ -1,3 +1,6 @@ package -public fun foo(/*0*/ n: kotlin.Nothing, /*1*/ nn: kotlin.Nothing?): kotlin.Unit +public fun test1(/*0*/ n: kotlin.Nothing): kotlin.Unit +public fun test2(/*0*/ n: kotlin.Nothing?): kotlin.Unit +public fun test3(/*0*/ n: kotlin.Nothing?): kotlin.Unit + diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.fir.kt index 329e962da76..b26ac7c24c2 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.fir.kt @@ -1,3 +1,4 @@ +// FIR_IDE_IGNORE // !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts // SKIP_TXT @@ -10,13 +11,15 @@ fun case_1(value_1: Any?) { // TESTCASE NUMBER: 2 fun case_2(value_1: Int?) { funWithReturnsAndInvertCondition(value_1 != null) - println(value_1.inc()) + println(value_1.inc()) // inc resolves to compiler/tests-spec/testData/diagnostics/helpers/classes.kt which accepts `Class?` + println(value_1.unaryPlus()) } // TESTCASE NUMBER: 3 fun case_3(value_1: Int?) { funWithReturns(value_1 == null) - println(value_1.inc()) + println(value_1.inc()) // inc resolves to compiler/tests-spec/testData/diagnostics/helpers/classes.kt which accepts `Class?` + println(value_1.unaryPlus()) } // TESTCASE NUMBER: 4 @@ -43,7 +46,7 @@ object case_7_object { } fun case_7() { funWithReturns(case_7_object.prop_1 == null) - case_7_object.prop_1.inc() + case_7_object.prop_1.inc() // inc resolves to compiler/tests-spec/testData/diagnostics/helpers/classes.kt which accepts `Class?` } // TESTCASE NUMBER: 8 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.kt index ffed2829937..cc9598bbdd5 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/1.kt @@ -1,3 +1,4 @@ +// FIR_IDE_IGNORE // !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts // SKIP_TXT @@ -20,12 +21,14 @@ fun case_1(value_1: Any?) { fun case_2(value_1: Int?) { funWithReturnsAndInvertCondition(value_1 != null) println(value_1.inc()) + println(value_1.unaryPlus()) } // TESTCASE NUMBER: 3 fun case_3(value_1: Int?) { funWithReturns(value_1 == null) println(value_1.inc()) + println(value_1.unaryPlus()) } // TESTCASE NUMBER: 4 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.fir.kt index 606ab8ac0fe..365eac57bed 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.fir.kt @@ -116,7 +116,7 @@ fun case_5(value_1: Number?, value_2: String?) { fun case_6(value_1: Number, value_2: String?, value_3: Any?) { when (value_3.case_6(value_1, value_2)) { true -> { - println(value_3.equals("")) + println(value_3.equals("")) // OK because `value_3` is `Nothing?` and `equals` resolves to `kotlin/text/equals`, which has `String?` as receiver type. println(value_2.length) } false -> { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.kt index 961c5eb14f5..9fb5fb79adb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/neg/8.kt @@ -126,7 +126,7 @@ fun case_5(value_1: Number?, value_2: String?) { fun case_6(value_1: Number, value_2: String?, value_3: Any?) { when (value_3.case_6(value_1, value_2)) { true -> { - println(value_3.equals("")) + println(value_3.equals("")) // OK because `value_3` is `Nothing?` and `equals` resolves to `kotlin/text/equals`, which has `String?` as receiver type. println(value_2.length) } false -> { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt index 610fe758b7e..80cbe68278d 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt @@ -87,7 +87,7 @@ fun case_6(x: EmptyClass?) { // TESTCASE NUMBER: 7 fun case_7() { - if (nullableNumberProperty != null || nullableNumberProperty != null is Boolean) { + if (nullableNumberProperty != null || nullableNumberProperty != null is Boolean) { nullableNumberProperty nullableNumberProperty.equals(null) nullableNumberProperty.propT @@ -262,8 +262,8 @@ fun case_16() { // TESTCASE NUMBER: 17 val case_17 = if (nullableIntProperty == null == true == false) 0 else { - nullableIntProperty - nullableIntProperty.java + nullableIntProperty + nullableIntProperty.java } //TESTCASE NUMBER: 18 @@ -440,18 +440,18 @@ fun case_25(b: Boolean) { // TESTCASE NUMBER: 26 fun case_26(a: ((Float) -> Int?)?, b: Float?) { if (a != null == true == false && b != null == true == false) { - val x = a(b) + val x = a(b) if (x != null == true === false) { - x - x.equals(null) - x.propT - x.propAny - x.propNullableT - x.propNullableAny - x.funT() - x.funAny() - x.funNullableT() - x.funNullableAny() + x + x.equals(null) + x.propT + x.propAny + x.propNullableT + x.propNullableAny + x.funT() + x.funAny() + x.funNullableT() + x.funNullableAny() } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.fir.kt index 835c827a936..bc7adcdad47 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.fir.kt @@ -35,8 +35,8 @@ fun case_4() { var x: Boolean? = true if (x != null) { false || when { else -> {x = null; true} } - x - x.not() + x + x.not() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt index fe612d46382..10e9e6475a1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt @@ -37,8 +37,8 @@ fun case_3() { var x: Boolean? = true if (x != null) { false || when { else -> { x = null; true} } - x - x.not() + x + x.not() } } @@ -64,7 +64,7 @@ fun case_4() { fun case_5() { var x: Boolean? = true if (x != null) { - when { else -> { x = null; false} } || x.not() + when { else -> { x = null; false} } || x.not() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/16.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/16.fir.kt index c1789a86e4a..04cddb7b248 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/16.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/16.fir.kt @@ -18,8 +18,8 @@ fun case_1(x: ClassWithCustomEquals) { // TESTCASE NUMBER: 2 fun case_2(x: ClassWithCustomEquals) { if (x == null) { - x - x.inv() + x + x.inv() } } @@ -76,8 +76,8 @@ fun case_6(x: ClassWithCustomEquals) { // TESTCASE NUMBER: 7 fun case_7(x: ClassWithCustomEquals) { if ((x != null) == false) { - x - x.inv() + x + x.inv() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/2.fir.kt index 39807322f91..f0581369fc6 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/2.fir.kt @@ -37,8 +37,8 @@ fun case_4(x: Any) { // TESTCASE NUMBER: 5 fun case_5(x: Any?) { if (!(x !is Nothing?)) { - x - x?.inv() + x + x?.inv() } } @@ -61,16 +61,16 @@ fun case_7(x: Any) { // TESTCASE NUMBER: 8 fun case_8(x: Any?) { if (!(x is Nothing?)) else { - x - x?.inv() + x + x?.inv() } } // TESTCASE NUMBER: 9 fun case_9(x: Any?) { if (!!(x !is Nothing?)) else { - x - x?.inv() + x + x?.inv() } } @@ -85,7 +85,7 @@ fun case_10(x: Any?) { // TESTCASE NUMBER: 11 fun case_11(x: Any?) { if (x is Nothing?) { - x - x?.inv() + x + x?.inv() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/21.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/21.fir.kt index ffd0875039f..69066976d1a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/21.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/21.fir.kt @@ -13,7 +13,7 @@ class Case1 { val y = this if (y.x != null) { x = null - x + x this.x y.x y.x.inv() diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt index 2edb2787f86..7aa1e2cb1fb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt @@ -31,8 +31,8 @@ inline fun case_3() { var x: T? = 10 as T x = null if (x is K) { - x.equals(10) - x + x.equals(10) + x println(1) } } @@ -61,8 +61,8 @@ inline fun case_6() { var x: T? = 10 as T if (x is K) { x = null - x.equals(10) - x + x.equals(10) + x println(1) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/29.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/29.fir.kt index 13e674b4c5e..b6580141e18 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/29.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/29.fir.kt @@ -9,8 +9,8 @@ fun case_1(a: Any?) { if (true) continue } - a - a.equals(10) + a + a.equals(10) } // TESTCASE NUMBER: 2 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/32.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/32.fir.kt index 4c60decae17..74683ea16fe 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/32.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/32.fir.kt @@ -12,8 +12,8 @@ fun stringArg(number: String) {} */ fun case_1(x: Int?) { if (x == null) { - stringArg(x!!) - x + stringArg(x!!) + x } } @@ -37,8 +37,8 @@ fun case_2(x: Int?, y: Nothing?) { fun case_3(x: Int?) { if (x == null) { x as Int - stringArg(x) - x + stringArg(x) + x } } @@ -50,8 +50,8 @@ fun case_3(x: Int?) { fun case_4(x: Int?) { if (x == null) { x!! - stringArg(x) - x + stringArg(x) + x } } @@ -64,7 +64,7 @@ fun case_5(x: Int?) { if (x == null) { var y = x y!! - stringArg(y) - y + stringArg(y) + y } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/33.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/33.fir.kt index fa890f0a159..5af73610fa4 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/33.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/33.fir.kt @@ -12,7 +12,7 @@ fun nullableStringArg(number: String?) {} */ fun case_1(x: Int?) { if (x == null) { - nullableStringArg(x) + nullableStringArg(x) } } @@ -34,7 +34,7 @@ fun case_2(x: Int?, y: Nothing?) { */ fun case_3(x: Int?) { if (x == null) { - nullableStringArg(x) + nullableStringArg(x) } } @@ -45,7 +45,7 @@ fun case_3(x: Int?) { */ fun case_4(x: Int?) { if (x == null) { - nullableStringArg(x) + nullableStringArg(x) } } @@ -57,6 +57,6 @@ fun case_4(x: Int?) { fun case_5(x: Int?) { if (x == null) { var y = x - nullableStringArg(y) + nullableStringArg(y) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/34.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/34.fir.kt index 92bca11edee..da9b5bad900 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/34.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/34.fir.kt @@ -106,8 +106,8 @@ fun case_9() { x = null break } while (x!!.length > 1) - x - x.length + x + x.length } // TESTCASE NUMBER: 10 @@ -117,8 +117,8 @@ fun case_10() { x = null break } while ((x as String).length > 1) - x - x.length + x + x.length } // TESTCASE NUMBER: 11 @@ -128,8 +128,8 @@ fun case_11() { x = null break } while (x!!) - x - x.not() + x + x.not() } // TESTCASE NUMBER: 12 @@ -141,8 +141,8 @@ fun case_12() { x = null break } while (true && x!!) - x - x.not() + x + x.not() } // TESTCASE NUMBER: 13 @@ -154,8 +154,8 @@ fun case_13() { x = null break } while (false && x!!) - x - x.not() + x + x.not() } // TESTCASE NUMBER: 14 @@ -167,8 +167,8 @@ fun case_14() { x = null break } while (true || x!!) - x - x.not() + x + x.not() } // TESTCASE NUMBER: 15 @@ -180,8 +180,8 @@ fun case_15() { x = null break } while (!(false && x!!)) - x - x.not() + x + x.not() } /* diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/35.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/35.fir.kt index 4edde03cecb..f11eb436217 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/35.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/35.fir.kt @@ -37,8 +37,8 @@ fun case_3() { var x: String? x = "Test" println("${try { } finally { x = null }}") - x - x.length + x + x.length } /* @@ -76,8 +76,8 @@ fun case_6() { var x: String? x = "Test" println("${try { } catch (e: Exception) { } finally { x = null }}") - x - x.length + x + x.length } /* @@ -115,6 +115,6 @@ fun case_9() { var x: String? x = "Test" println("${when (null) { else -> x = null } }") - x - x.length + x + x.length } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/38.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/38.fir.kt index 1df5b95afd5..3aa69a52639 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/38.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/38.fir.kt @@ -15,8 +15,8 @@ fun case_1() { break@outer } } - x - x.length + x + x.length } /* @@ -32,8 +32,8 @@ fun case_2() { break@outer } } - x - x.length + x + x.length } /* @@ -145,8 +145,8 @@ fun case_9() { inner@ do { x = null } while (x != null) - x - x.length + x + x.length } } @@ -158,8 +158,8 @@ fun case_10() { inner@ do { x = null } while (true) - x - x.length + x + x.length } } @@ -172,7 +172,7 @@ fun case_11() { x = null break } while (x == null) - x - x.length + x + x.length } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/39.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/39.fir.kt index 7a57b8a3cfb..434d6567a63 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/39.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/39.fir.kt @@ -151,8 +151,8 @@ fun case_12() { while (true) { y += if (x == null) break else 10 } - x - x.inv() + x + x.inv() } // TESTCASE NUMBER: 13 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt index f3d63fbc9c5..7140a8c0e2a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt @@ -122,7 +122,7 @@ fun case_6(x: EmptyClass?) { // TESTCASE NUMBER: 7 fun case_7() { - if (nullableNumberProperty != null || nullableNumberProperty != null) { + if (nullableNumberProperty != null || nullableNumberProperty != null) { nullableNumberProperty nullableNumberProperty.equals(null) nullableNumberProperty.propT @@ -1302,11 +1302,11 @@ open class Case29(a: Int?, val b: Float?, private val c: Unit?, protected val d: if (w != null || this.w != null) this.w s = null - s.hashCode() - s - if (s != null) s - if (this.s != null) s - if (s != null || this.s != null) s + s.hashCode() + s + if (s != null) s + if (this.s != null) s + if (s != null || this.s != null) s if (s != null || this.s != null) this.s } @@ -2346,11 +2346,11 @@ sealed class Case30(a: Int?, val b: Float?, private val c: Unit?, protected val if (w != null || this.w != null) this.w s = null - s.hashCode() - s - if (s != null) s - if (this.s != null) s - if (s != null || this.s != null) s + s.hashCode() + s + if (s != null) s + if (this.s != null) s + if (s != null || this.s != null) s if (s != null || this.s != null) this.s } @@ -3391,11 +3391,11 @@ enum class Case31(a: Int?, val b: Float?, private val c: Unit?, protected val d: if (w != null || this.w != null) this.w s = null - s.hashCode() - s - if (s != null) s - if (this.s != null) s - if (s != null || this.s != null) s + s.hashCode() + s + if (s != null) s + if (this.s != null) s + if (s != null || this.s != null) s if (s != null || this.s != null) this.s } @@ -4039,11 +4039,11 @@ object Case32 { if (w != null || this.w != null) this.w s = null - s.hashCode() - s - if (s != null) s - if (this.s != null) s - if (s != null || this.s != null) s + s.hashCode() + s + if (s != null) s + if (this.s != null) s + if (s != null || this.s != null) s if (s != null || this.s != null) this.s } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.fir.kt index 0817a8c0c67..69a3d64e304 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.fir.kt @@ -288,7 +288,7 @@ fun case_11(b: Boolean) { if (z != null || b) { } else { - ? & ?")!>z + ? & kotlin.Nothing?")!>z } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt index 08b2302cb78..6e7bf0fdb0e 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt @@ -16,14 +16,14 @@ import otherpackage.* // TESTCASE NUMBER: 1 fun case_1(x: Any?) { if (x == null) { - x + x } } // TESTCASE NUMBER: 2 fun case_2(x: Nothing?) { if (x == null) { - x + x } } @@ -38,7 +38,7 @@ fun case_3() { // TESTCASE NUMBER: 4 fun case_4(x: Char?) { if (x == null && true) { - x + x } } @@ -46,7 +46,7 @@ fun case_4(x: Char?) { fun case_5() { val x: Unit? = null - if (x == null) x + if (x == null) x } // TESTCASE NUMBER: 6 @@ -54,7 +54,7 @@ fun case_6(x: EmptyClass?) { val y = true if (x == null && !y) { - x + x } } @@ -67,8 +67,8 @@ fun case_7() { // TESTCASE NUMBER: 8 fun case_8(x: TypealiasNullableString) { - if (x == null && x == null) - x + if (x == null && x == null) + x } /* @@ -105,7 +105,7 @@ fun case_11(x: TypealiasNullableString?, y: TypealiasNullableString) { if (y == null) { if (nullableStringProperty != null) { if (z == null) { - x + x } } } @@ -172,7 +172,7 @@ fun case_14() { // TESTCASE NUMBER: 15 fun case_15(x: TypealiasNullableString) { val t = if (x != null) "" else { - x + x } } @@ -187,13 +187,13 @@ fun case_16() { // TESTCASE NUMBER: 17 val case_17 = if (nullableIntProperty !== null) 0 else { - nullableIntProperty + nullableIntProperty } //TESTCASE NUMBER: 18 fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?) { if (a == null) { - a + a } } @@ -249,17 +249,17 @@ fun case_21() { // TESTCASE NUMBER: 22 fun case_22(a: (() -> Unit)?) { if (a == null) { - ? & kotlin.Function0?")!>a + ? & kotlin.Nothing?")!>a } } // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int?)?, b: Float?) { if (a == null && b == null) { - ? & kotlin.Function1?")!>a - b + ? & kotlin.Nothing?")!>a + b if (a != null) { - ? & kotlin.Function1")!>a + ? & kotlin.Nothing")!>a } } } @@ -290,13 +290,13 @@ fun case_25(b: Boolean) { val z = ?")!>y() if (z == null) { - ? & ?")!>z + ? & kotlin.Nothing?")!>z } } } // TESTCASE NUMBER: 26 -fun case_26(a: Int?, b: Int? = if (a !== null) 0 else a) { +fun case_26(a: Int?, b: Int? = if (a !== null) 0 else a) { a b } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/37.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/37.fir.kt index aea2c696795..51af182ea16 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/37.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/37.fir.kt @@ -98,7 +98,7 @@ fun case_9(x: Boolean?) { while (x ?: return) while (x == null) - x + x x.equals(10) } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.fir.kt index d191413dbc5..f515a60d163 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.fir.kt @@ -19,14 +19,14 @@ import otherpackage.* // TESTCASE NUMBER: 1 fun case_1(x: Any) { if (x === null) { - x + x } } // TESTCASE NUMBER: 2 fun case_2(x: Nothing) { if (x == null) { - x + x } } @@ -41,7 +41,7 @@ fun case_3() { // TESTCASE NUMBER: 4 fun case_4(x: Char) { if (x == null && true) { - x + x } } @@ -49,7 +49,7 @@ fun case_4(x: Char) { fun case_5() { val x: Unit = kotlin.Unit - if (x == null) x + if (x == null) x } // TESTCASE NUMBER: 6 @@ -57,7 +57,7 @@ fun case_6(x: EmptyClass) { val y = true if (x == null && !y) { - x + x } } @@ -70,7 +70,7 @@ fun case_7() { // TESTCASE NUMBER: 8 fun case_8(x: TypealiasString) { - if (x == null && x == null) x + if (x == null && x == null) x } // TESTCASE NUMBER: 9 @@ -78,7 +78,7 @@ fun case_9(x: TypealiasString) { if (x != null) { } else if (false) { - x + x } } @@ -103,7 +103,7 @@ fun case_11(x: TypealiasString, y: TypealiasString) { if (y == null) { if (stringProperty != null) { if (false || false || false || z == null || false) { - x + x } } } @@ -112,14 +112,14 @@ fun case_11(x: TypealiasString, y: TypealiasString) { // TESTCASE NUMBER: 12 fun case_12(x: TypealiasString, y: TypealiasString) = if (x != null) "1" - else if (y !== null) x + else if (y !== null) x else "-1" // TESTCASE NUMBER: 13 fun case_13(x: otherpackage.EmptyClass13) = - if (x != null) { + if (x != null) { 1 - } else x + } else x // TESTCASE NUMBER: 14 class A14 { @@ -179,7 +179,7 @@ fun case_16() { val x: TypealiasNothing = return if (x == null) { - x + x } } @@ -195,7 +195,7 @@ val case_17 = if (true && true && in //TESTCASE NUMBER: 18 fun case_18(a: DeepObject.A.B.C.D.E.F.G.J) { if (a == null) { - a + a } } @@ -256,7 +256,7 @@ fun case_22(a: (() -> Unit)) { // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int), b: Float) { if (a == null && b == null) { - val x = a(b) + val x = a(b) if (x !== null) { x } @@ -276,13 +276,13 @@ fun case_24(a: ((() -> Unit) -> Unit), b: (() -> Unit)) { } // TESTCASE NUMBER: 25 -fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) , kotlin.Unit> & kotlin.Function1, kotlin.Unit>")!>a else {{}}) { +fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) , kotlin.Unit> & kotlin.Nothing")!>a else {{}}) { , kotlin.Unit>")!>a , kotlin.Unit>")!>b } // TESTCASE NUMBER: 26 -fun case_26(a: Int, b: Int = if (a === null) a else 0) { +fun case_26(a: Int, b: Int = if (a === null) a else 0) { a b } 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 687fd142356..b8a015181a2 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 @@ -133,10 +133,10 @@ fun case_13(x: Any?) { */ fun case_14(x: Any?) { if (x == null) { - x - x?.equals(10) - x!!.equals(10) - x.equals(10) + x + x?.equals(10) + x!!.equals(10) + x.equals(10) } } @@ -147,10 +147,10 @@ fun case_14(x: Any?) { */ fun case_15(x: Any?) { if (x !== null) else { - x - x?.equals(10) - x!!.equals(10) - x.equals(10) + x + x?.equals(10) + x!!.equals(10) + x.equals(10) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/52.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/52.fir.kt index caa259385cb..6e911ccbe5e 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/52.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/52.fir.kt @@ -12,7 +12,7 @@ fun case_1(x: Int?) = x fun case_1() { var x: Int? = 10 x = null - case_1(x) + case_1(x) } // TESTCASE NUMBER: 2 @@ -21,7 +21,7 @@ fun case_2(x: Nothing?) = x fun case_2() { var x: Int? = 10 x = null - case_2(x) + case_2(x) } // TESTCASE NUMBER: 3 @@ -29,7 +29,7 @@ fun case_3(x: String?) = x fun case_3() { var x: Int? = 10 x = null - case_3(x) + case_3(x) } /* @@ -42,7 +42,7 @@ fun Int?.case_4() = this fun case_4() { var x: Int? = 10 x = null - x.case_4() + x.case_4() } // TESTCASE NUMBER: 5 @@ -51,7 +51,7 @@ fun Nothing?.case_5() = this fun case_5() { var x: Int? = 10 x = null - x.case_5() + x.case_5() } // TESTCASE NUMBER: 6 @@ -59,7 +59,7 @@ fun String?.case_6() = this fun case_6() { var x: Int? = 10 x = null - x.case_6() + x.case_6() } /* @@ -72,7 +72,7 @@ fun T.case_7() = this fun case_7() { var x: Int? = 10 x = null - x.case_7() + x.case_7() } // TESTCASE NUMBER: 8 @@ -81,7 +81,7 @@ fun T.case_8() = this fun case_8() { var x: Int? = 10 x = null - x.case_8() + x.case_8() } // TESTCASE NUMBER: 9 @@ -89,7 +89,7 @@ fun T.case_9() = this fun case_9() { var x: Int? = 10 x = null - x.case_9() + x.case_9() } /* @@ -102,7 +102,7 @@ fun Int> T?.case_10() = this fun case_10() { var x: Int? = 10 x = null - x.case_10() + x.case_10() } // TESTCASE NUMBER: 11 @@ -110,5 +110,5 @@ fun String> T?.case_11() = this fun case_11() { var x: Int? = 10 x = null - x.case_11() + x.case_11() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.fir.kt index 501fe32d597..be7ca52ba40 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.fir.kt @@ -20,7 +20,7 @@ fun case_2() { var x: Int? = 10 var y = { x = null } if (x != null) { - val z = case_2(x) + val z = case_2(x) z } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/60.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/60.fir.kt index f43dabe635c..4c0608a642a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/60.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/60.fir.kt @@ -10,7 +10,7 @@ fun case_1() { inner@ do { x = null } while (x == null) - x - x.length + x + x.length } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt index aa7e83aa357..d7b4737b9b5 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt @@ -154,7 +154,7 @@ fun case_10(x: Any): String { */ fun case_11(x: Any?): String? { if (x is Nothing?) { - return when(x) { + return when(x) { null -> null } } @@ -168,7 +168,7 @@ fun case_11(x: Any?): String? { */ fun case_12(x: Any?): String? { if (x == null) { - return when(x) { + return when(x) { null -> null } } @@ -182,7 +182,7 @@ fun case_12(x: Any?): String? { */ fun case_13(x: Any?): String? { if (x === null) { - return when(x) { + return when(x) { null -> null } } @@ -196,7 +196,7 @@ fun case_13(x: Any?): String? { */ fun case_14(x: Any?): String? { x as Nothing? - return when(x) { + return when(x) { null -> null } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt index 8e5c36ba0e3..7e7f0616be1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt @@ -14,8 +14,8 @@ fun case_1(x: Any?) { // TESTCASE NUMBER: 2 fun case_2(x: Any?) { (x as Nothing?)!! - x - x.inv() + x + x.inv() } // TESTCASE NUMBER: 3 @@ -37,8 +37,8 @@ fun case_4(x: Any?) { // TESTCASE NUMBER: 5 fun case_5(x: Any?) { if (x as Nothing? is Nothing) { - x - x.inv() + x + x.inv() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt index 0b11b0ed40e..f04e9a1c6da 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt @@ -39,7 +39,7 @@ fun case_1(x: Any?) { */ fun case_2(x: Nothing?) { if (x !== null && x !== null) { - x + x } } @@ -81,16 +81,16 @@ fun case_5() { val x: Unit? = null if (x !== null || x !== null && x !== null || x !== null && x !== null) { - x - x.equals(null) - x.propT - x.propAny - x.propNullableT - x.propNullableAny - x.funT() - x.funAny() - x.funNullableT() - x.funNullableAny() + x + x.equals(null) + x.propT + x.propAny + x.propNullableT + x.propNullableAny + x.funT() + x.funAny() + x.funNullableT() + x.funNullableAny() } } @@ -115,7 +115,7 @@ fun case_6(x: Class?) { // TESTCASE NUMBER: 7 fun case_7() { val x: EmptyObject? = null - if (x != null || x != null || x != null) { + if (x != null || x != null || x != null) { x x.equals(null) x.propT diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/70.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/70.fir.kt index 46a14698e57..fc3f8ae9fb8 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/70.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/70.fir.kt @@ -25,7 +25,7 @@ fun case_2(): Int? { val x: Int? = null return when (x != null) { false -> { - x + x } else -> null } @@ -53,7 +53,7 @@ fun case_4(): Int? { val x: Int? = null return when (x == null) { true -> { - x + x } else -> null } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/8.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/8.fir.kt index 14f935ba289..de86f6b1798 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/8.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/8.fir.kt @@ -57,16 +57,16 @@ fun case_3(a: Inv?) { if (a != null) { val b = a if (a == null) { - ? & Inv")!>b - ? & Inv")!>b.equals(null) - ? & Inv")!>b.propT - ? & Inv")!>b.propAny - ? & Inv")!>b.propNullableT - ? & Inv")!>b.propNullableAny - ? & Inv")!>b.funT() - ? & Inv")!>b.funAny() - ? & Inv")!>b.funNullableT() - ? & Inv")!>b.funNullableAny() + ? & kotlin.Nothing")!>b + ? & kotlin.Nothing")!>b.equals(null) + ? & kotlin.Nothing")!>b.propT + ? & kotlin.Nothing")!>b.propAny + ? & kotlin.Nothing")!>b.propNullableT + ? & kotlin.Nothing")!>b.propNullableAny + ? & kotlin.Nothing")!>b.funT() + ? & kotlin.Nothing")!>b.funAny() + ? & kotlin.Nothing")!>b.funNullableT() + ? & kotlin.Nothing")!>b.funNullableAny() } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/9.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/9.fir.kt index 4a9c0045867..9457f5ceffd 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/9.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/9.fir.kt @@ -61,7 +61,7 @@ fun case_3(a: Inv?) { if (a != null) { val b = a if (a == null) - ? & Inv")!>b + ? & kotlin.Nothing")!>b ? & Inv")!>b.equals(null) ? & Inv")!>b.propT ? & Inv")!>b.propAny