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 49d77bc4450..84f51667df3 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 @@ -276,9 +276,16 @@ class Fir2IrImplicitCastInserter( override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: IrElement): IrElement { // We don't want an implicit cast to Nothing?. This expression just encompasses nullability after null check. return if (smartCastExpression.isStable && smartCastExpression.smartcastTypeWithoutNullableNothing == null) { - implicitCastOrExpression(data as IrExpression, smartCastExpression.resolvedType) + val smartcastedType = smartCastExpression.resolvedType + val approximatedType = smartcastedType.approximateForIrOrNull() + if (approximatedType != null) { + if (smartCastExpression.originalExpression.resolvedType.isSubtypeOf(approximatedType, session)) { + return data + } + } + implicitCastOrExpression(data as IrExpression, approximatedType ?: smartcastedType) } else { - data as IrExpression + data } } @@ -410,4 +417,8 @@ class Fir2IrImplicitCastInserter( return lowerBound.isMarkedNullable != upperBound.isMarkedNullable } } + + private fun ConeKotlinType.approximateForIrOrNull(): ConeKotlinType? { + return session.typeApproximator.approximateToSuperType(this, TypeApproximatorConfiguration.FrontendToBackendTypesApproximation) + } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 76ffd81649c..75e271c4bf7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -1280,10 +1280,11 @@ class CallAndReferenceGenerator( symbol.fir.receiverParameter?.typeRef?.let { receiverType -> with(visitor.implicitCastInserter) { val extensionReceiver = qualifiedAccess.extensionReceiver!! + val substitutor = qualifiedAccess.buildSubstitutorByCalledCallable() it.cast( extensionReceiver, extensionReceiver.resolvedType, - receiverType.coneType, + substitutor.substituteOrSelf(receiverType.coneType), ) } } ?: it diff --git a/compiler/testData/codegen/box/annotations/javaTargetOnPrimaryCtorParameter.fir.ir.txt b/compiler/testData/codegen/box/annotations/javaTargetOnPrimaryCtorParameter.fir.ir.txt index 90e1e4c9938..3e573277564 100644 --- a/compiler/testData/codegen/box/annotations/javaTargetOnPrimaryCtorParameter.fir.ir.txt +++ b/compiler/testData/codegen/box/annotations/javaTargetOnPrimaryCtorParameter.fir.ir.txt @@ -105,8 +105,7 @@ FILE fqName: fileName:/test.kt CALL 'public abstract fun (): kotlin.String? declared in kotlin.reflect.KClass' type=kotlin.String? origin=GET_PROPERTY $this: CALL 'public final fun (): kotlin.reflect.KClass> declared in kotlin.jvm' type=kotlin.reflect.KClass origin=GET_PROPERTY : @[FlexibleNullability] kotlin.Annotation? - $receiver: TYPE_OP type=kotlin.Annotation origin=IMPLICIT_NOTNULL typeOperand=kotlin.Annotation - GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in .box.' type=@[FlexibleNullability] kotlin.Annotation? origin=null + $receiver: GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in .box.' type=@[FlexibleNullability] kotlin.Annotation? origin=null WHEN type=kotlin.String origin=null BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ diff --git a/compiler/testData/codegen/box/annotations/targetOnPrimaryCtorParameter.fir.ir.txt b/compiler/testData/codegen/box/annotations/targetOnPrimaryCtorParameter.fir.ir.txt index 9048d43f01c..612187e801c 100644 --- a/compiler/testData/codegen/box/annotations/targetOnPrimaryCtorParameter.fir.ir.txt +++ b/compiler/testData/codegen/box/annotations/targetOnPrimaryCtorParameter.fir.ir.txt @@ -264,8 +264,7 @@ FILE fqName: fileName:/targetOnPrimaryCtorParameter.kt CALL 'public abstract fun (): kotlin.String? declared in kotlin.reflect.KClass' type=kotlin.String? origin=GET_PROPERTY $this: CALL 'public final fun (): kotlin.reflect.KClass> declared in kotlin.jvm' type=kotlin.reflect.KClass origin=GET_PROPERTY : @[FlexibleNullability] kotlin.Annotation? - $receiver: TYPE_OP type=kotlin.Annotation origin=IMPLICIT_NOTNULL typeOperand=kotlin.Annotation - GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in .box.' type=@[FlexibleNullability] kotlin.Annotation? origin=null + $receiver: GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in .box.' type=@[FlexibleNullability] kotlin.Annotation? origin=null WHEN type=kotlin.String origin=null BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ diff --git a/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt b/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt index 8a25b4194d9..bf2c426eac6 100644 --- a/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt @@ -47,8 +47,7 @@ FILE fqName: fileName:/bangbang.kt then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): {T0 of kotlin.internal.ir.CHECK_NOT_NULL & Any} declared in kotlin.internal.ir' type=kotlin.Any origin=EXCLEXCL : kotlin.Any - arg0: TYPE_OP type=kotlin.Any? origin=IMPLICIT_CAST typeOperand=kotlin.Any? - GET_VAR 'a: X of .test4 declared in .test4' type=X of .test4 origin=null + arg0: GET_VAR 'a: X of .test4 declared in .test4' type=X of .test4 origin=null WHEN type=kotlin.Unit origin=IF BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String? diff --git a/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt b/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt index 8f34ac79669..a2f3e8ce7fe 100644 --- a/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/bangbang.fir.kt.txt @@ -21,7 +21,7 @@ fun useString(s: String) { fun test4(a: X) { when { - a is String? -> CHECK_NOT_NULL(arg0 = a /*as Any? */) /*~> Unit */ + a is String? -> CHECK_NOT_NULL(arg0 = a) /*~> Unit */ } when { a is String? -> useString(s = CHECK_NOT_NULL(arg0 = a /*as Any */)) diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.ir.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.ir.txt index 3b0b58c9db6..7b685dd99de 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.ir.txt @@ -180,8 +180,7 @@ FILE fqName: fileName:/caoWithAdaptationForSam.kt VAR IR_TEMPORARY_VARIABLE name:tmp_6 type:.A [val] GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:kotlin.Any [val] - TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'fn: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + GET_VAR 'fn: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null $receiver: GET_VAR 'val tmp_6: .A declared in .test4' type=.A origin=null i: GET_VAR 'val tmp_7: kotlin.Any declared in .test4' type=kotlin.Any origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt index 5b4246ebd33..19c5bc615d9 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt @@ -84,7 +84,7 @@ fun test4(fn: Function1) { fn is IFoo -> { // BLOCK { // BLOCK val tmp_6: A = A - val tmp_7: Any = fn /*as Any */ + val tmp_7: Any = fn tmp_6.set(i = tmp_7, newValue = tmp_6.get(i = tmp_7).plus(other = 1)) } } diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.ir.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.ir.txt index bb0736fa96d..75515488fb6 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.ir.txt @@ -44,8 +44,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null then: BLOCK type=kotlin.Unit origin=null CALL 'public final fun run1 (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null - r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null + r: GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null FUN name:test2 visibility:public modality:FINAL <> (a:.KRunnable) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:.KRunnable BLOCK_BODY @@ -53,8 +52,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt TYPE_OP type=kotlin.Function0 origin=CAST typeOperand=kotlin.Function0 GET_VAR 'a: .KRunnable declared in .test2' type=.KRunnable origin=null CALL 'public final fun run1 (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null - r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: .KRunnable declared in .test2' type=.KRunnable origin=null + r: GET_VAR 'a: .KRunnable declared in .test2' type=.KRunnable origin=null FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY @@ -64,10 +62,8 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null then: BLOCK type=kotlin.Unit origin=null CALL 'public final fun run2 (r1: .KRunnable, r2: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null - r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null - r2: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + r1: GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + r2: GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0, b:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 VALUE_PARAMETER name:b index:1 type:kotlin.Function0 @@ -78,8 +74,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null then: BLOCK type=kotlin.Unit origin=null CALL 'public final fun run2 (r1: .KRunnable, r2: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null - r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null + r1: GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null r2: TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable GET_VAR 'b: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit @@ -125,8 +120,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null CALL 'public final fun run1 (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null r: TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable - TYPE_OP type=kotlin.Function origin=IMPLICIT_CAST typeOperand=kotlin.Function - GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null + GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null FUN name:test7a visibility:public modality:FINAL (a:T of .test7a) returnType:kotlin.Unit TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function1] reified:false VALUE_PARAMETER name:a index:0 type:T of .test7a @@ -136,8 +130,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: T of .test7a declared in .test7a' type=T of .test7a origin=null CALL 'public final fun run1 (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null r: TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable - TYPE_OP type=kotlin.Function origin=IMPLICIT_CAST typeOperand=kotlin.Function - GET_VAR 'a: T of .test7a declared in .test7a' type=T of .test7a origin=null + GET_VAR 'a: T of .test7a declared in .test7a' type=T of .test7a origin=null FUN name:test7b visibility:public modality:FINAL (a:T of .test7b) returnType:kotlin.Unit TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function1; kotlin.Function0] reified:false VALUE_PARAMETER name:a index:0 type:T of .test7b diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt index 300f379e1b9..fcf30b8eb81 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionsWithSmartCasts.fir.kt.txt @@ -20,20 +20,20 @@ fun test0(a: T) where T : KRunnable, T : Function0 { fun test1(a: Function0) { when { a is KRunnable -> { // BLOCK - run1(r = a /*as Any */) + run1(r = a) } } } fun test2(a: KRunnable) { a as Function0 /*~> Unit */ - run1(r = a /*as Any */) + run1(r = a) } fun test3(a: Function0) { when { a is KRunnable -> { // BLOCK - run2(r1 = a /*as Any */, r2 = a /*as Any */) + run2(r1 = a, r2 = a) } } } @@ -41,7 +41,7 @@ fun test3(a: Function0) { fun test4(a: Function0, b: Function0) { when { a is KRunnable -> { // BLOCK - run2(r1 = a /*as Any */, r2 = b /*-> KRunnable */) + run2(r1 = a, r2 = b /*-> KRunnable */) } } } @@ -70,12 +70,12 @@ fun test6(a: Any) { fun test7(a: Function1) { a as Function0 /*~> Unit */ - run1(r = a /*as Function */ /*-> KRunnable */) + run1(r = a /*-> KRunnable */) } fun > test7a(a: T) { a as Function0 /*~> Unit */ - run1(r = a /*as Function */ /*-> KRunnable */) + run1(r = a /*-> KRunnable */) } fun test7b(a: T) where T : Function1, T : Function0 { diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt index aca763cf2eb..28cb466a511 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt @@ -40,8 +40,7 @@ FILE fqName: fileName:/implicitCastToTypeParameter.kt BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of . GET_VAR ': .Foo.> declared in .' type=.Foo.> origin=null - then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR ': .Foo.> declared in .' type=.Foo.> origin=null + then: GET_VAR ': .Foo.> declared in .' type=.Foo.> origin=null BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Null type=kotlin.Nothing? value=null diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt index cdebb451a5c..0a88b204020 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt @@ -12,7 +12,7 @@ interface Foo { val Foo.asT: T? inline get(): T? { return when { - is T -> /*as Any */ + is T -> else -> null } } @@ -33,3 +33,4 @@ class Bar { } } + diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt index 566a922e1c5..36e97d7b23b 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt @@ -8,8 +8,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null then: BLOCK type=kotlin.Unit origin=null CALL 'public open fun runStatic (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null - r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null + r: GET_VAR 'a: kotlin.Function0 declared in .test1' type=kotlin.Function0 origin=null FUN name:test2 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY @@ -20,8 +19,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt then: BLOCK type=kotlin.Unit origin=null CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test2' type=kotlin.Function0 origin=null + r: GET_VAR 'a: kotlin.Function0 declared in .test2' type=kotlin.Function0 origin=null FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY @@ -32,10 +30,8 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt then: BLOCK type=kotlin.Unit origin=null CALL 'public open fun run2 (r1: @[FlexibleNullability] java.lang.Runnable?, r2: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null - r2: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + r1: GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + r2: GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0, b:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 VALUE_PARAMETER name:b index:1 type:kotlin.Function0 @@ -47,8 +43,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt then: BLOCK type=kotlin.Unit origin=null CALL 'public open fun run2 (r1: @[FlexibleNullability] java.lang.Runnable?, r2: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null + r1: GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null r2: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? GET_VAR 'b: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit @@ -98,8 +93,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null r: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? - TYPE_OP type=kotlin.Function origin=IMPLICIT_CAST typeOperand=kotlin.Function - GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null + GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt index 2203f8def80..5ae781b9b52 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt @@ -1,7 +1,7 @@ fun test1(a: Function0) { when { a is Runnable -> { // BLOCK - runStatic(r = a /*as Any */) + runStatic(r = a) } } } @@ -9,7 +9,7 @@ fun test1(a: Function0) { fun test2(a: Function0) { when { a is Runnable -> { // BLOCK - J().run1(r = a /*as Any */) + J().run1(r = a) } } } @@ -17,7 +17,7 @@ fun test2(a: Function0) { fun test3(a: Function0) { when { a is Runnable -> { // BLOCK - J().run2(r1 = a /*as Any */, r2 = a /*as Any */) + J().run2(r1 = a, r2 = a) } } } @@ -25,7 +25,7 @@ fun test3(a: Function0) { fun test4(a: Function0, b: Function0) { when { a is Runnable -> { // BLOCK - J().run2(r1 = a /*as Any */, r2 = b /*-> @FlexibleNullability Runnable? */) + J().run2(r1 = a, r2 = b /*-> @FlexibleNullability Runnable? */) } } } @@ -54,7 +54,7 @@ fun test6(a: Any) { fun test7(a: Function1) { a as Function0 /*~> Unit */ - J().run1(r = a /*as Function */ /*-> @FlexibleNullability Runnable? */) + J().run1(r = a /*-> @FlexibleNullability Runnable? */) } fun test8(a: Function0) { diff --git a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.ir.txt b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.ir.txt index 20426d10a7c..76f47955ca2 100644 --- a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.ir.txt @@ -49,8 +49,7 @@ FILE fqName: fileName:/smartCastsWithDestructuring.kt then: RETURN type=kotlin.Nothing from='public final fun test (x: .I1): kotlin.Unit declared in ' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.I1 [val] - TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - GET_VAR 'x: .I1 declared in .test' type=.I1 origin=null + GET_VAR 'x: .I1 declared in .test' type=.I1 origin=null VAR name:c1 type:kotlin.Int [val] CALL 'public final fun component1 (): kotlin.Int declared in ' type=kotlin.Int origin=COMPONENT_N(index=1) $receiver: GET_VAR 'val tmp_0: .I1 declared in .test' type=.I1 origin=null diff --git a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt index 220ba40444b..37e99655dd8 100644 --- a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.kt.txt @@ -18,7 +18,8 @@ fun test(x: I1) { when { x !is I2 -> return Unit } - val tmp_0: I1 = x /*as Any */ + val tmp_0: I1 = x val c1: Int = tmp_0.component1() val c2: String = tmp_0 /*as I2 */.component2() } + diff --git a/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.ir.txt b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.ir.txt index ee9c0f5f5b5..4c79bd7c4f5 100644 --- a/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.ir.txt @@ -254,8 +254,7 @@ FILE fqName: fileName:/suspendConversionOnArbitraryExpression.kt TYPE_OP type=kotlin.coroutines.SuspendFunction0 origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0 GET_VAR 'a: kotlin.Function0 declared in .testSmartCastVsSuspendConversion' type=kotlin.Function0 origin=null CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null - sfn: TYPE_OP type=kotlin.Function origin=IMPLICIT_CAST typeOperand=kotlin.Function - GET_VAR 'a: kotlin.Function0 declared in .testSmartCastVsSuspendConversion' type=kotlin.Function0 origin=null + sfn: GET_VAR 'a: kotlin.Function0 declared in .testSmartCastVsSuspendConversion' type=kotlin.Function0 origin=null FUN name:testSmartCastOnVarVsSuspendConversion visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY @@ -265,8 +264,7 @@ FILE fqName: fileName:/suspendConversionOnArbitraryExpression.kt TYPE_OP type=kotlin.coroutines.SuspendFunction0 origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0 GET_VAR 'var b: kotlin.Function0 declared in .testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0 origin=null CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null - sfn: TYPE_OP type=kotlin.Function origin=IMPLICIT_CAST typeOperand=kotlin.Function - GET_VAR 'var b: kotlin.Function0 declared in .testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0 origin=null + sfn: GET_VAR 'var b: kotlin.Function0 declared in .testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0 origin=null FUN name:testIntersectionVsSuspendConversion visibility:public modality:FINAL (x:T of .testIntersectionVsSuspendConversion) returnType:kotlin.Unit TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function0; kotlin.coroutines.SuspendFunction0] reified:false VALUE_PARAMETER name:x index:0 type:T of .testIntersectionVsSuspendConversion diff --git a/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt index 2fd04615cdc..9eb213112ad 100644 --- a/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/suspendConversionOnArbitraryExpression.fir.kt.txt @@ -175,13 +175,13 @@ fun testSmartCastOnVarWithSuspendConversion(a: Any) { fun testSmartCastVsSuspendConversion(a: Function0) { a as SuspendFunction0 /*~> Unit */ - useSuspend(sfn = a /*as Function */) + useSuspend(sfn = a) } fun testSmartCastOnVarVsSuspendConversion(a: Function0) { var b: Function0 = a b as SuspendFunction0 /*~> Unit */ - useSuspend(sfn = b /*as Function */) + useSuspend(sfn = b) } fun testIntersectionVsSuspendConversion(x: T) where T : Function0, T : SuspendFunction0 {