diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index 70a811c31d7..860d2ae6d02 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.removeAnnotations +import org.jetbrains.kotlin.ir.types.withHasQuestionMark import org.jetbrains.kotlin.ir.util.classId import org.jetbrains.kotlin.ir.util.coerceToUnitIfNeeded import org.jetbrains.kotlin.ir.util.parentAsClass @@ -209,6 +210,9 @@ class Fir2IrImplicitCastInserter( expectedType.isUnit -> { coerceToUnitIfNeeded(type, irBuiltIns) } + valueType.isNullabilityFlexible() && valueType.canBeNull && !expectedType.acceptsNullValues() -> { + insertImplicitNotNullCastIfNeeded(expression) + } valueType.hasEnhancedNullability() && !expectedType.acceptsNullValues() -> { insertImplicitNotNullCastIfNeeded(expression) } @@ -218,8 +222,16 @@ class Fir2IrImplicitCastInserter( } } + private fun FirTypeRef.isNullabilityFlexible(): Boolean { + if (hasFlexibleNullability()) { + return true + } + val flexibility = coneTypeSafe() ?: return false + return flexibility.lowerBound.isMarkedNullable != flexibility.upperBound.isMarkedNullable + } + private fun FirTypeRef.acceptsNullValues(): Boolean = - isMarkedNullable == true || hasEnhancedNullability() + canBeNull || hasEnhancedNullability() private fun IrExpression.insertImplicitNotNullCastIfNeeded(expression: FirExpression): IrExpression { // [TypeOperatorLowering] will retrieve the source (from start offset to end offset) as an assertion message. @@ -227,9 +239,11 @@ class Fir2IrImplicitCastInserter( if (expression.source == null) { return this } + // Cast type massage 1. Remove @EnhancedNullability + // Cast type massage 2. Convert it to a non-null variant (in case of @FlexibleNullability) val castType = type.removeAnnotations { it.symbol.owner.parentAsClass.classId == CompilerConeAttributes.EnhancedNullability.ANNOTATION_CLASS_ID - } + }.withHasQuestionMark(false) return IrTypeOperatorCallImpl( this.startOffset, this.endOffset, 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 28022b87cdd..5da22a8d3f5 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 @@ -138,3 +138,20 @@ private fun ConeTypeParameterType.hasNotNullUpperBound(): Boolean { } } } + +val FirTypeRef.canBeNull: Boolean + get() = coneType.canBeNull + +val ConeKotlinType.canBeNull: Boolean + get() { + if (isMarkedNullable) { + return true + } + return when (this) { + is ConeFlexibleType -> upperBound.canBeNull + is ConeDefinitelyNotNullType -> false + is ConeTypeParameterType -> this.lookupTag.typeParameterSymbol.fir.bounds.any { it.canBeNull } + is ConeIntersectionType -> intersectedTypes.any { it.canBeNull } + else -> isNullable + } + } \ No newline at end of file diff --git a/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapGetOrDefault.kt b/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapGetOrDefault.kt index 544a5e8212c..97c450bcb5f 100644 --- a/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapGetOrDefault.kt +++ b/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapGetOrDefault.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // JVM_TARGET: 1.8 // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapRemove2.kt b/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapRemove2.kt index e23d2ed3aec..5458fc23ea0 100644 --- a/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapRemove2.kt +++ b/compiler/testData/codegen/box/casts/javaInterop/nullCheckOnMapRemove2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // JVM_TARGET: 1.8 // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/fullJdk/platformTypeAssertionStackTrace.kt b/compiler/testData/codegen/box/fullJdk/platformTypeAssertionStackTrace.kt index 3c51754ba66..b5ba5b94fac 100644 --- a/compiler/testData/codegen/box/fullJdk/platformTypeAssertionStackTrace.kt +++ b/compiler/testData/codegen/box/fullJdk/platformTypeAssertionStackTrace.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FULL_JDK diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt index f75c88a32e9..ce426fcf75d 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: test.kt fun f(x: String) = "Fail 1" diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue/stringVsTConstrained.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue/stringVsTConstrained.kt index f6e9bbf03be..6d2e7491f41 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue/stringVsTConstrained.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue/stringVsTConstrained.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // FILE: stringVsTConstrained.kt fun useTConstrained(xs: Array, fn: () -> T) = fn() diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt index e45b126c20d..9255c5d583c 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: test.kt fun f(x: String) = "Fail 1" diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt index c6c2eae56f3..6c89da9e8a8 100644 --- a/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR import java.util.ArrayList fun foo(): Any { diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt index de9551a47ab..3633b5db67b 100644 --- a/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { fun add(element: T) {} } diff --git a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/deterministicNotNullChecks.kt b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/deterministicNotNullChecks.kt index f180d292a36..9ba12a721a6 100644 --- a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/deterministicNotNullChecks.kt +++ b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/deterministicNotNullChecks.kt @@ -1,8 +1,4 @@ // FILE: test/CallableDescriptor.java -// IGNORE_BACKEND_FIR: JVM_IR -// Here FIR adds implicit NOT_NULL cast for `origin`, resulting in an assertion being added, -// which is the correct (yet mismatching) behavior, according to https://youtrack.jetbrains.com/issue/KT-35656 - // JVM_IR: // Here in 'original in emptySet()' T = '@EnhancedNullability CallableDescriptor' is inferred for 'Iterable.contains(T)'. // Using value of '@EnhancedNullability CallableDescriptor' type where '@EnhancedNullability CallableDescriptor' is expected diff --git a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNull.kt b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNull.kt index 8db917deb8a..758216e51e3 100644 --- a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNull.kt +++ b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNull.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // FILE: j/J.java package j; diff --git a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNullTwice.kt b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNullTwice.kt index 01ac2aa4da5..ff2f16e7fda 100644 --- a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNullTwice.kt +++ b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/expressionValueIsNotNullTwice.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // FILE: j/J.java package j; diff --git a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/notNullExpressionValueTwice_1_4.kt b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/notNullExpressionValueTwice_1_4.kt index a80f2c8a9e1..6cfa2e956a5 100644 --- a/compiler/testData/codegen/bytecodeText/nullCheckOptimization/notNullExpressionValueTwice_1_4.kt +++ b/compiler/testData/codegen/bytecodeText/nullCheckOptimization/notNullExpressionValueTwice_1_4.kt @@ -1,5 +1,4 @@ // !API_VERSION: LATEST -// IGNORE_BACKEND_FIR: JVM_IR // FILE: j/J.java package j; diff --git a/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.txt b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.txt index f7841f19a32..48a7778edda 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.txt +++ b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.fir.txt @@ -2,5 +2,6 @@ FILE fqName: fileName:/implicitCastOnPlatformType.kt FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test (): kotlin.String declared in ' - CALL 'public open fun getProperty (p0: kotlin.String?): kotlin.String? declared in java.lang.System' type=kotlin.String? origin=null - p0: CONST String type=kotlin.String value="test" + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun getProperty (p0: kotlin.String?): kotlin.String? declared in java.lang.System' type=kotlin.String? origin=null + p0: CONST String type=kotlin.String value="test" diff --git a/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.txt b/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.txt index 5119c9fe99e..e51da36277b 100644 --- a/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.txt +++ b/compiler/testData/ir/irText/expressions/nullCheckOnLambdaReturn.fir.txt @@ -25,7 +25,8 @@ FILE fqName: fileName:/nullCheckOnLambdaReturn.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.Any declared in .test1' - CALL 'public open fun foo (): kotlin.String? declared in .J' type=kotlin.String? origin=null + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun foo (): kotlin.String? declared in .J' type=kotlin.String? origin=null PROPERTY name:test2 visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.Function0 visibility:private [final,static] EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.txt b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.txt index d25cef9cccb..7eefb793044 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.txt @@ -7,15 +7,16 @@ FILE fqName: fileName:/genericSamSmartcast.kt if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.A<*> GET_VAR 'x: kotlin.Any declared in .f' type=kotlin.Any origin=null then: RETURN type=kotlin.Nothing from='public final fun f (x: kotlin.Any): kotlin.String declared in ' - CALL 'public open fun call (block: .A.I.A?>?): kotlin.String? declared in .A' type=kotlin.String? origin=null - $this: TYPE_OP type=.A<*> origin=IMPLICIT_CAST typeOperand=.A<*> - GET_VAR 'x: kotlin.Any declared in .f' type=kotlin.Any origin=null - block: TYPE_OP type=.A.I? origin=SAM_CONVERSION typeOperand=.A.I? - FUN_EXPR type=kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (y:kotlin.Any?) returnType:kotlin.String? - VALUE_PARAMETER name:y index:0 type:kotlin.Any? - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (y: kotlin.Any?): kotlin.String? declared in .f' - CONST String type=kotlin.String value="OK" + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun call (block: .A.I.A?>?): kotlin.String? declared in .A' type=kotlin.String? origin=null + $this: TYPE_OP type=.A<*> origin=IMPLICIT_CAST typeOperand=.A<*> + GET_VAR 'x: kotlin.Any declared in .f' type=kotlin.Any origin=null + block: TYPE_OP type=.A.I? origin=SAM_CONVERSION typeOperand=.A.I? + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (y:kotlin.Any?) returnType:kotlin.String? + VALUE_PARAMETER name:y index:0 type:kotlin.Any? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (y: kotlin.Any?): kotlin.String? declared in .f' + CONST String type=kotlin.String value="OK" RETURN type=kotlin.Nothing from='public final fun f (x: kotlin.Any): kotlin.String declared in ' CONST String type=kotlin.String value="Fail" diff --git a/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt index 76d3d8cba80..bb21c34f27d 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt @@ -33,4 +33,5 @@ FILE fqName: fileName:/samConstructors.kt RETURN type=kotlin.Nothing from='local final fun (a: kotlin.Int?, b: kotlin.Int?): kotlin.Int declared in .test4' CALL 'public final fun minus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=MINUS $this: GET_VAR 'a: kotlin.Int? declared in .test4.' type=kotlin.Int? origin=null - other: GET_VAR 'b: kotlin.Int? declared in .test4.' type=kotlin.Int? origin=null + other: TYPE_OP type=kotlin.Int origin=IMPLICIT_NOTNULL typeOperand=kotlin.Int + GET_VAR 'b: kotlin.Int? declared in .test4.' type=kotlin.Int? origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt index 7ac01e935d9..2fb5458168d 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt @@ -141,7 +141,8 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt $this: GET_VAR 'val tmp_1: .Q<@[FlexibleNullability] kotlin.String, kotlin.String?>? [val] declared in .test2' type=.Q<@[FlexibleNullability] kotlin.String, kotlin.String?>? origin=null CALL 'public final fun use (x: kotlin.Any, y: kotlin.Any): kotlin.Unit declared in ' type=kotlin.Unit origin=null x: GET_VAR 'val x: @[FlexibleNullability] kotlin.String [val] declared in .test2' type=@[FlexibleNullability] kotlin.String origin=null - y: GET_VAR 'val y: kotlin.String? [val] declared in .test2' type=kotlin.String? origin=null + y: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_VAR 'val y: kotlin.String? [val] declared in .test2' type=kotlin.String? origin=null FUN name:test2Desugared visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY VAR name:tmp type:.Q<@[FlexibleNullability] kotlin.String, kotlin.String?>? [val] @@ -154,7 +155,8 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt $this: GET_VAR 'val tmp: .Q<@[FlexibleNullability] kotlin.String, kotlin.String?>? [val] declared in .test2Desugared' type=.Q<@[FlexibleNullability] kotlin.String, kotlin.String?>? origin=null CALL 'public final fun use (x: kotlin.Any, y: kotlin.Any): kotlin.Unit declared in ' type=kotlin.Unit origin=null x: GET_VAR 'val x: @[FlexibleNullability] kotlin.String [val] declared in .test2Desugared' type=@[FlexibleNullability] kotlin.String origin=null - y: GET_VAR 'val y: kotlin.String? [val] declared in .test2Desugared' type=kotlin.String? origin=null + y: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_VAR 'val y: kotlin.String? [val] declared in .test2Desugared' type=kotlin.String? origin=null FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:.Q<@[FlexibleNullability] kotlin.String, kotlin.String?> [val] @@ -168,7 +170,8 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt $this: GET_VAR 'val tmp_2: .Q<@[FlexibleNullability] kotlin.String, kotlin.String?> [val] declared in .test3' type=.Q<@[FlexibleNullability] kotlin.String, kotlin.String?> origin=null CALL 'public final fun use (x: kotlin.Any, y: kotlin.Any): kotlin.Unit declared in ' type=kotlin.Unit origin=null x: GET_VAR 'val x: @[FlexibleNullability] kotlin.String [val] declared in .test3' type=@[FlexibleNullability] kotlin.String origin=null - y: GET_VAR 'val y: kotlin.String? [val] declared in .test3' type=kotlin.String? origin=null + y: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_VAR 'val y: kotlin.String? [val] declared in .test3' type=kotlin.String? origin=null FUN name:test4 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.collections.IndexedValue<.P?> [val] @@ -185,4 +188,5 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt $this: GET_VAR 'val tmp_3: kotlin.collections.IndexedValue<.P?> [val] declared in .test4' type=kotlin.collections.IndexedValue<.P?> origin=null CALL 'public final fun use (x: kotlin.Any, y: kotlin.Any): kotlin.Unit declared in ' type=kotlin.Unit origin=null x: GET_VAR 'val x: kotlin.Int [val] declared in .test4' type=kotlin.Int origin=null - y: GET_VAR 'val y: .P? [val] declared in .test4' type=.P? origin=null + y: TYPE_OP type=.P origin=IMPLICIT_NOTNULL typeOperand=.P + GET_VAR 'val y: .P? [val] declared in .test4' type=.P? origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt index 50826e6b84d..9cf32cd3d9e 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt @@ -75,7 +75,8 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_3: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListUse' type=kotlin.collections.MutableIterator<.P?> origin=null CALL 'public final fun use (s: .P): kotlin.Unit declared in ' type=kotlin.Unit origin=null - s: GET_VAR 'val x: .P? [val] declared in .testForInListUse' type=.P? origin=null + s: TYPE_OP type=.P origin=IMPLICIT_NOTNULL typeOperand=.P + GET_VAR 'val x: .P? [val] declared in .testForInListUse' type=.P? origin=null CALL 'public open fun use (s: @[EnhancedNullability] .P): kotlin.Unit declared in .J' type=kotlin.Unit origin=null s: GET_VAR 'val x: .P? [val] declared in .testForInListUse' type=.P? origin=null FUN name:testForInArrayUse visibility:public modality:FINAL <> (j:.J) returnType:kotlin.Unit @@ -94,7 +95,8 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=.P? origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_4: kotlin.collections.Iterator<.P?> [val] declared in .testForInArrayUse' type=kotlin.collections.Iterator<.P?> origin=null CALL 'public final fun use (s: .P): kotlin.Unit declared in ' type=kotlin.Unit origin=null - s: GET_VAR 'val x: .P? [val] declared in .testForInArrayUse' type=.P? origin=null + s: TYPE_OP type=.P origin=IMPLICIT_NOTNULL typeOperand=.P + GET_VAR 'val x: .P? [val] declared in .testForInArrayUse' type=.P? origin=null CALL 'public open fun use (s: @[EnhancedNullability] .P): kotlin.Unit declared in .J' type=kotlin.Unit origin=null s: GET_VAR 'val x: .P? [val] declared in .testForInArrayUse' type=.P? origin=null CLASS INTERFACE name:K modality:ABSTRACT visibility:public superTypes:[kotlin.Any] diff --git a/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt b/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt index 2e3c14c17b6..63b46434e8f 100644 --- a/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt @@ -31,8 +31,9 @@ FILE fqName: fileName:/explicitEqualsAndCompareToCallsOnPlatformTypeReceiv CALL 'public open fun compareTo (other: kotlin.Double): kotlin.Int [operator] declared in kotlin.Double' type=kotlin.Int origin=null $this: CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToPlatform' type=.JavaClass origin=null - other: CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null - $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToPlatform' type=.JavaClass origin=null + other: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToPlatform' type=.JavaClass origin=null FUN name:testPlatformCompareToKotlin visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Int $receiver: VALUE_PARAMETER name: type:.JavaClass BLOCK_BODY @@ -47,5 +48,6 @@ FILE fqName: fileName:/explicitEqualsAndCompareToCallsOnPlatformTypeReceiv RETURN type=kotlin.Nothing from='public final fun testKotlinCompareToPlatform (): kotlin.Int declared in ' CALL 'public open fun compareTo (other: kotlin.Double): kotlin.Int [operator] declared in kotlin.Double' type=kotlin.Int origin=null $this: CONST Double type=kotlin.Double value=0.0 - other: CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null - $this: GET_VAR ': .JavaClass declared in .testKotlinCompareToPlatform' type=.JavaClass origin=null + other: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testKotlinCompareToPlatform' type=.JavaClass origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.txt b/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.txt index 887af12416c..48b734647ea 100644 --- a/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/implicitNotNullOnPlatformType.fir.txt @@ -63,16 +63,19 @@ FILE fqName: fileName:/implicitNotNullOnPlatformType.kt FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun f (s: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null - s: CALL 'public open fun s (): kotlin.String? declared in .J' type=kotlin.String? origin=null + s: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun s (): kotlin.String? declared in .J' type=kotlin.String? origin=null CALL 'public final fun f (s: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null - s: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:STRING type:kotlin.String? visibility:public [static]' type=kotlin.String? origin=GET_PROPERTY + s: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:STRING type:kotlin.String? visibility:public [static]' type=kotlin.String? origin=GET_PROPERTY FUN name:testContains visibility:public modality:FINAL <> (m:.MySet) returnType:kotlin.Unit VALUE_PARAMETER name:m index:0 type:.MySet BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun contains (element: kotlin.String): kotlin.Boolean [operator] declared in .MySet' type=kotlin.Boolean origin=null $this: GET_VAR 'm: .MySet declared in .testContains' type=.MySet origin=null - element: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:STRING type:kotlin.String? visibility:public [static]' type=kotlin.String? origin=GET_PROPERTY + element: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:STRING type:kotlin.String? visibility:public [static]' type=kotlin.String? origin=GET_PROPERTY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun contains (element: kotlin.String): kotlin.Boolean [operator] declared in .MySet' type=kotlin.Boolean origin=null $this: GET_VAR 'm: .MySet declared in .testContains' type=.MySet origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.txt b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.txt index 9072f71313c..d06da6b5448 100644 --- a/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/nullCheckOnLambdaResult/stringVsTConstrained.fir.txt @@ -18,4 +18,5 @@ FILE fqName: fileName:/stringVsTConstrained.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.String declared in .testWithNullCheck' - CALL 'public open fun string (): kotlin.String? declared in .J' type=kotlin.String? origin=null + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun string (): kotlin.String? declared in .J' type=kotlin.String? origin=null diff --git a/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.txt b/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.txt index 39d947804da..8c9701788ee 100644 --- a/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.txt +++ b/compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.fir.txt @@ -21,6 +21,7 @@ FILE fqName: fileName:/smartCastOnFieldReceiverOfGenericType.kt TYPE_OP type=.JCell origin=CAST typeOperand=.JCell GET_VAR 'a: kotlin.Any declared in .testGetField' type=kotlin.Any origin=null RETURN type=kotlin.Nothing from='public final fun testGetField (a: kotlin.Any): kotlin.String declared in ' - GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of .JCell? visibility:public' type=kotlin.String? origin=GET_PROPERTY - receiver: TYPE_OP type=.JCell origin=IMPLICIT_CAST typeOperand=.JCell - GET_VAR 'a: kotlin.Any declared in .testGetField' type=kotlin.Any origin=null + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of .JCell? visibility:public' type=kotlin.String? origin=GET_PROPERTY + receiver: TYPE_OP type=.JCell origin=IMPLICIT_CAST typeOperand=.JCell + GET_VAR 'a: kotlin.Any declared in .testGetField' type=kotlin.Any origin=null