[FIR2IR] Properly insert casts for smartcasts in argument position

Previously cast inserter didn't consider expected type for arguments
  of function calls

^KT-63257 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-11-07 17:41:22 +02:00
committed by Space Team
parent c70a6425f5
commit 8578a0bf6a
30 changed files with 292 additions and 33 deletions
@@ -51308,6 +51308,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -51308,6 +51308,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -234,6 +234,19 @@ class Fir2IrImplicitCastInserter(
}
}
internal fun IrExpression.insertCastForSmartcastWithIntersection(
argumentType: ConeKotlinType,
expectedType: ConeKotlinType
): IrExpression {
if (argumentType !is ConeIntersectionType) return this
val approximatedArgumentType = argumentType.approximateForIrOrNull() ?: argumentType
if (approximatedArgumentType.isSubtypeOf(expectedType, session)) return this
return findComponentOfIntersectionForExpectedType(argumentType, expectedType)?.let {
implicitCast(this, it.toIrType())
} ?: this
}
private fun ConeKotlinType.acceptsNullValues(): Boolean {
return canBeNull || hasEnhancedNullability
}
@@ -333,9 +346,15 @@ class Fir2IrImplicitCastInserter(
}
}
for (componentType in receiverExpressionType.intersectedTypes) {
if (AbstractTypeChecker.isSubtypeOf(session.typeContext, componentType, receiverType)) {
return implicitCastOrExpression(originalIrReceiver, componentType, typeOrigin)
return findComponentOfIntersectionForExpectedType(receiverExpressionType, receiverType)?.let {
implicitCastOrExpression(originalIrReceiver, it, typeOrigin)
}
}
private fun findComponentOfIntersectionForExpectedType(type: ConeIntersectionType, expectedType: ConeKotlinType): ConeKotlinType? {
for (componentType in type.intersectedTypes) {
if (AbstractTypeChecker.isSubtypeOf(session.typeContext, componentType, expectedType)) {
return componentType
}
}
return null
@@ -1021,17 +1021,26 @@ class CallAndReferenceGenerator(
parameter: FirValueParameter?,
substitutor: ConeSubstitutor,
): IrExpression {
val parameterConeType = parameter?.returnTypeRef?.coneType
val unsubstitutedParameterType = parameter?.returnTypeRef?.coneType?.fullyExpandedType(session)
// Normally argument type should be correct itself.
// However, for deserialized annotations it's possible to have imprecise Array<Any> type
// for empty integer literal arguments.
// In this case we have to use parameter type itself which is more precise, like Array<String> or IntArray.
// See KT-62598 and its fix for details.
val expectedType = parameterConeType.takeIf { visitor.annotationMode && parameterConeType?.isArrayType == true }
val expectedType = unsubstitutedParameterType.takeIf { visitor.annotationMode && unsubstitutedParameterType?.isArrayType == true }
var irArgument = visitor.convertToIrExpression(argument, expectedType = expectedType)
if (parameterConeType != null) {
if (unsubstitutedParameterType != null) {
with(visitor.implicitCastInserter) {
irArgument = irArgument.cast(argument, argument.resolvedType, parameterConeType)
val argumentType = argument.resolvedType.fullyExpandedType(session)
if (argument is FirSmartCastExpression) {
val substitutedParameterType = substitutor.substituteOrSelf(unsubstitutedParameterType)
// here we should use a substituted parameter type to properly choose the component of an intersection type
// to provide a proper cast to the smartcasted type
irArgument = irArgument.insertCastForSmartcastWithIntersection(argumentType, substitutedParameterType)
}
// here we should pass unsubstituted parameter type to properly infer if the original type accepts null or not
// to properly insert nullability check
irArgument = irArgument.cast(argument, argumentType, unsubstitutedParameterType)
}
}
with(adapterGenerator) {
@@ -50733,6 +50733,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -50733,6 +50733,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -50733,6 +50733,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -0,0 +1,84 @@
FILE fqName:<root> fileName:/smartcastFromGenericToString.kt
CLASS CLASS name:Some modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Some<V of <root>.Some>
TYPE_PARAMETER name:V index:0 variance: superTypes:[kotlin.Any] reified:false
CONSTRUCTOR visibility:public <> (map:kotlin.collections.Map<kotlin.String, V of <root>.Some>) returnType:<root>.Some<V of <root>.Some> [primary]
VALUE_PARAMETER name:map index:0 type:kotlin.collections.Map<kotlin.String, V of <root>.Some>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Some modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:map visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:map type:kotlin.collections.Map<kotlin.String, V of <root>.Some> visibility:private [final]
EXPRESSION_BODY
GET_VAR 'map: kotlin.collections.Map<kotlin.String, V of <root>.Some> declared in <root>.Some.<init>' type=kotlin.collections.Map<kotlin.String, V of <root>.Some> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-map> visibility:public modality:FINAL <> ($this:<root>.Some<V of <root>.Some>) returnType:kotlin.collections.Map<kotlin.String, V of <root>.Some>
correspondingProperty: PROPERTY name:map visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Some<V of <root>.Some>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-map> (): kotlin.collections.Map<kotlin.String, V of <root>.Some> declared in <root>.Some'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:map type:kotlin.collections.Map<kotlin.String, V of <root>.Some> visibility:private [final]' type=kotlin.collections.Map<kotlin.String, V of <root>.Some> origin=null
receiver: GET_VAR '<this>: <root>.Some<V of <root>.Some> declared in <root>.Some.<get-map>' type=<root>.Some<V of <root>.Some> origin=null
FUN name:test visibility:public modality:FINAL <> ($this:<root>.Some<V of <root>.Some>, key:kotlin.String) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Some<V of <root>.Some>
VALUE_PARAMETER name:key index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test (key: kotlin.String): kotlin.String declared in <root>.Some'
BLOCK type=kotlin.String origin=WHEN
VAR name:value type:V of <root>.Some [val]
CALL 'public final fun getValue <K, V> (key: K of kotlin.collections.getValue): V of kotlin.collections.getValue declared in kotlin.collections' type=V of <root>.Some origin=null
<K>: kotlin.String
<V>: V of <root>.Some
$receiver: CALL 'public final fun <get-map> (): kotlin.collections.Map<kotlin.String, V of <root>.Some> declared in <root>.Some' type=kotlin.collections.Map<kotlin.String, V of <root>.Some> origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Some<V of <root>.Some> declared in <root>.Some.test' type=<root>.Some<V of <root>.Some> origin=null
key: GET_VAR 'key: kotlin.String declared in <root>.Some.test' type=kotlin.String origin=null
WHEN type=kotlin.String origin=WHEN
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String
GET_VAR 'val value: V of <root>.Some declared in <root>.Some.test' type=V of <root>.Some origin=null
then: CALL 'public final fun addK (s: kotlin.String): kotlin.String declared in <root>.Some' type=kotlin.String origin=null
$this: GET_VAR '<this>: <root>.Some<V of <root>.Some> declared in <root>.Some.test' type=<root>.Some<V of <root>.Some> origin=null
s: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR 'val value: V of <root>.Some declared in <root>.Some.test' type=V of <root>.Some origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Fail: "
GET_VAR 'val value: V of <root>.Some declared in <root>.Some.test' type=V of <root>.Some origin=null
FUN name:addK visibility:public modality:FINAL <> ($this:<root>.Some<V of <root>.Some>, s:kotlin.String) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Some<V of <root>.Some>
VALUE_PARAMETER name:s index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun addK (s: kotlin.String): kotlin.String declared in <root>.Some'
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=PLUS
$this: GET_VAR 's: kotlin.String declared in <root>.Some.addK' type=kotlin.String origin=null
other: CONST String type=kotlin.String value="K"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:x type:<root>.Some<kotlin.String> [val]
CONSTRUCTOR_CALL 'public constructor <init> (map: kotlin.collections.Map<kotlin.String, V of <root>.Some>) declared in <root>.Some' type=<root>.Some<kotlin.String> origin=null
<class: V>: kotlin.String
map: CALL 'public final fun mapOf <K, V> (pair: kotlin.Pair<K of kotlin.collections.mapOf, V of kotlin.collections.mapOf>): kotlin.collections.Map<K of kotlin.collections.mapOf, V of kotlin.collections.mapOf> declared in kotlin.collections' type=kotlin.collections.Map<kotlin.String, kotlin.String> origin=null
<K>: kotlin.String
<V>: kotlin.String
pair: CALL 'public final fun to <A, B> (that: B of kotlin.to): kotlin.Pair<A of kotlin.to, B of kotlin.to> declared in kotlin' type=kotlin.Pair<kotlin.String, kotlin.String> origin=null
<A>: kotlin.String
<B>: kotlin.String
$receiver: CONST String type=kotlin.String value="key"
that: CONST String type=kotlin.String value="O"
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public final fun test (key: kotlin.String): kotlin.String declared in <root>.Some' type=kotlin.String origin=null
$this: GET_VAR 'val x: <root>.Some<kotlin.String> declared in <root>.box' type=<root>.Some<kotlin.String> origin=null
key: CONST String type=kotlin.String value="key"
@@ -0,0 +1,22 @@
// ISSUE: KT-62863
// FIR_IDENTICAL
// WITH_STDLIB
// DUMP_IR
class Some<V : Any>(val map: Map<String, V>) {
fun test(key: String): String {
return when (val value = map.getValue(key)) {
is String -> addK(value)
else -> "Fail: $value"
}
}
fun addK(s: String): String {
return s + "K"
}
}
fun box(): String {
val x = Some<String>(mapOf("key" to "O"))
return x.test("key")
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_K2: WASM
// WITH_STDLIB
// FILE: externals.js
@@ -229,4 +228,4 @@ fun box(): String {
}
return "OK"
}
}
@@ -44,7 +44,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
r: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test2 visibility:public modality:FINAL <> (a:<root>.KRunnable) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.KRunnable
BLOCK_BODY
@@ -62,8 +63,10 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public final fun run2 (r1: <root>.KRunnable, r2: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r2: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r1: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r2: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>, b:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
VALUE_PARAMETER name:b index:1 type:kotlin.Function0<kotlin.Unit>
@@ -74,7 +77,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public final fun run2 (r1: <root>.KRunnable, r2: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
r1: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
r2: TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
GET_VAR 'b: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
@@ -101,7 +105,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
r: GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
r: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
@@ -20,7 +20,7 @@ fun <T> test0(a: T) where T : KRunnable, T : Function0<Unit> {
fun test1(a: Function0<Unit>) {
when {
a is KRunnable -> { // BLOCK
run1(r = a)
run1(r = a /*as KRunnable */)
}
}
}
@@ -33,7 +33,7 @@ fun test2(a: KRunnable) {
fun test3(a: Function0<Unit>) {
when {
a is KRunnable -> { // BLOCK
run2(r1 = a, r2 = a)
run2(r1 = a /*as KRunnable */, r2 = a /*as KRunnable */)
}
}
}
@@ -41,7 +41,7 @@ fun test3(a: Function0<Unit>) {
fun test4(a: Function0<Unit>, b: Function0<Unit>) {
when {
a is KRunnable -> { // BLOCK
run2(r1 = a, r2 = b /*-> KRunnable */)
run2(r1 = a /*as KRunnable */, r2 = b /*-> KRunnable */)
}
}
}
@@ -58,7 +58,7 @@ fun test5x(a: Any) {
when {
a is KRunnable -> { // BLOCK
a /*as KRunnable */ as Function0<Unit> /*~> Unit */
run1(r = a)
run1(r = a /*as KRunnable */)
}
}
}
@@ -8,7 +8,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public open fun runStatic (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test2 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
@@ -19,7 +20,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
then: BLOCK type=kotlin.Unit origin=null
CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
@@ -30,8 +32,10 @@ FILE fqName:<root> 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 <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r2: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r1: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
r2: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>, b:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
VALUE_PARAMETER name:b index:1 type:kotlin.Function0<kotlin.Unit>
@@ -43,7 +47,8 @@ FILE fqName:<root> 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 <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
r1: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
r2: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable?
GET_VAR 'b: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
@@ -72,7 +77,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r: GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
@@ -1,7 +1,7 @@
fun test1(a: Function0<Unit>) {
when {
a is Runnable -> { // BLOCK
runStatic(r = a)
runStatic(r = a /*as Runnable */)
}
}
}
@@ -9,7 +9,7 @@ fun test1(a: Function0<Unit>) {
fun test2(a: Function0<Unit>) {
when {
a is Runnable -> { // BLOCK
J().run1(r = a)
J().run1(r = a /*as Runnable */)
}
}
}
@@ -17,7 +17,7 @@ fun test2(a: Function0<Unit>) {
fun test3(a: Function0<Unit>) {
when {
a is Runnable -> { // BLOCK
J().run2(r1 = a, r2 = a)
J().run2(r1 = a /*as Runnable */, r2 = a /*as Runnable */)
}
}
}
@@ -25,7 +25,7 @@ fun test3(a: Function0<Unit>) {
fun test4(a: Function0<Unit>, b: Function0<Unit>) {
when {
a is Runnable -> { // BLOCK
J().run2(r1 = a, r2 = b /*-> @FlexibleNullability Runnable? */)
J().run2(r1 = a /*as Runnable */, r2 = b /*-> @FlexibleNullability Runnable? */)
}
}
}
@@ -42,7 +42,7 @@ fun test5x(a: Any) {
when {
a is Runnable -> { // BLOCK
a /*as Runnable */ as Function0<Unit> /*~> Unit */
J().run1(r = a)
J().run1(r = a /*as Runnable */)
}
}
}
@@ -254,7 +254,8 @@ FILE fqName:<root> fileName:/suspendConversionOnArbitraryExpression.kt
TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
sfn: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
sfn: TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:testSmartCastOnVarVsSuspendConversion visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
@@ -264,7 +265,8 @@ FILE fqName:<root> fileName:/suspendConversionOnArbitraryExpression.kt
TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
sfn: GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
sfn: TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:testIntersectionVsSuspendConversion visibility:public modality:FINAL <T> (x:T of <root>.testIntersectionVsSuspendConversion) returnType:kotlin.Unit
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function0<kotlin.Unit>; kotlin.coroutines.SuspendFunction0<kotlin.Unit>] reified:false
VALUE_PARAMETER name:x index:0 type:T of <root>.testIntersectionVsSuspendConversion
@@ -175,13 +175,13 @@ fun testSmartCastOnVarWithSuspendConversion(a: Any) {
fun testSmartCastVsSuspendConversion(a: Function0<Unit>) {
a as SuspendFunction0<Unit> /*~> Unit */
useSuspend(sfn = a)
useSuspend(sfn = a /*as SuspendFunction0<Unit> */)
}
fun testSmartCastOnVarVsSuspendConversion(a: Function0<Unit>) {
var b: Function0<Unit> = a
b as SuspendFunction0<Unit> /*~> Unit */
useSuspend(sfn = b)
useSuspend(sfn = b /*as SuspendFunction0<Unit> */)
}
fun <T> testIntersectionVsSuspendConversion(x: T) where T : Function0<Unit>, T : SuspendFunction0<Unit> {
@@ -47739,6 +47739,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -50733,6 +50733,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -50733,6 +50733,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
@@ -40816,6 +40816,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@TestMetadata("smartcastOnImplicitDispatchReceiver.kt")
public void testSmartcastOnImplicitDispatchReceiver() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastOnImplicitDispatchReceiver.kt");
@@ -35109,6 +35109,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -35109,6 +35109,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -35109,6 +35109,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -35109,6 +35109,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastOnDynamic.kt")
public void testSmartcastOnDynamic() throws Exception {
@@ -38795,6 +38795,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {
@@ -39793,6 +39793,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {
@@ -38297,6 +38297,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {
@@ -38796,6 +38796,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {
@@ -34785,6 +34785,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {
@@ -34785,6 +34785,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
}
@Test
@TestMetadata("smartcastFromGenericToString.kt")
public void testSmartcastFromGenericToString() throws Exception {
runTest("compiler/testData/codegen/box/smartCasts/smartcastFromGenericToString.kt");
}
@Test
@TestMetadata("smartcastToStarType.kt")
public void testSmartcastToStarType() throws Exception {