diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt index 7f46394fdd5..52760eebb9a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.isNullabilityFlexible import org.jetbrains.kotlin.types.typeUtil.makeNotNullable +import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.types.upperIfFlexible fun insertImplicitCasts(builtIns: KotlinBuiltIns, element: IrElement, symbolTable: SymbolTable) { @@ -203,7 +204,7 @@ class InsertImplicitCasts(private val builtIns: KotlinBuiltIns, private val symb implicitCast(nonNullValueType, IrTypeOperator.IMPLICIT_NOTNULL).cast(expectedType) } - KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType.makeNotNullable(), expectedType) -> + KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType, expectedType.makeNullable()) -> this KotlinBuiltIns.isInt(valueType) && notNullableExpectedType.isBuiltInIntegerType() -> diff --git a/compiler/testData/ir/irText/classes/dataClassesGeneric.kt b/compiler/testData/ir/irText/classes/dataClassesGeneric.kt index 11e8b7786a4..0ce8c4ed2c5 100644 --- a/compiler/testData/ir/irText/classes/dataClassesGeneric.kt +++ b/compiler/testData/ir/irText/classes/dataClassesGeneric.kt @@ -1 +1,5 @@ -data class Test1(val x: T) \ No newline at end of file +data class Test1(val x: T) + +data class Test2(val x: T) + +data class Test3(val x: List) \ No newline at end of file diff --git a/compiler/testData/ir/irText/classes/dataClassesGeneric.txt b/compiler/testData/ir/irText/classes/dataClassesGeneric.txt index 746181a39e7..3a7f45197de 100644 --- a/compiler/testData/ir/irText/classes/dataClassesGeneric.txt +++ b/compiler/testData/ir/irText/classes/dataClassesGeneric.txt @@ -72,9 +72,7 @@ FILE fqName: fileName:/dataClassesGeneric.kt BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'hashCode(): Int' type=kotlin.Int origin=null - $this: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: - GET_VAR 'tmp1: T' type=T origin=null + $this: GET_VAR 'tmp1: T' type=T origin=null RETURN type=kotlin.Nothing from='hashCode(): Int' GET_VAR 'tmp0_result: Int' type=kotlin.Int origin=null FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:Test1, other:kotlin.Any?) returnType:Boolean flags: @@ -113,4 +111,205 @@ FILE fqName: fileName:/dataClassesGeneric.kt CONST Boolean type=kotlin.Boolean value=false RETURN type=kotlin.Nothing from='equals(Any?): Boolean' CONST Boolean type=kotlin.Boolean value=true - + CLASS CLASS name:Test2 modality:FINAL visibility:public flags:data + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Number] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Number modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> (x:T) returnType:Test2 flags:primary + VALUE_PARAMETER name:x index:0 type:T flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Test2' + PROPERTY name:x type:T visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:x type:T visibility:public flags:final + EXPRESSION_BODY + GET_VAR 'value-parameter x: T' type=T origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test2) returnType:T flags: + correspondingProperty: PROPERTY name:x type:T visibility:public modality:FINAL flags:val + $this: VALUE_PARAMETER name: type:Test2 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): T' + GET_FIELD 'x: T' type=T origin=null + receiver: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:Test2) returnType:T flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='component1(): T' + CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:Test2, x:T) returnType:Test2 flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + VALUE_PARAMETER name:x index:0 type:T flags: + EXPRESSION_BODY + CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='copy(T = ...): Test2' + CALL 'constructor Test2(T)' type=Test2 origin=null + : T + x: GET_VAR 'value-parameter x: T = ...' type=T origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:Test2) returnType:String flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='toString(): String' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value=Test2( + CONST String type=kotlin.String value=x= + CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + CONST String type=kotlin.String value=) + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:Test2) returnType:Int flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + BLOCK_BODY + VAR IR_TEMPORARY_VARIABLE name:tmp0_result type:kotlin.Int flags:var + CONST Int type=kotlin.Int value=0 + SET_VAR 'tmp0_result: Int' type=kotlin.Unit origin=EQ + CALL 'hashCode(): Int' type=kotlin.Int origin=null + $this: CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + RETURN type=kotlin.Nothing from='hashCode(): Int' + GET_VAR 'tmp0_result: Int' type=kotlin.Int origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:Test2, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + BLOCK_BODY + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'EQEQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQEQ + arg0: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + arg1: GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=Test2 + typeOperand: CLASS CLASS name:Test2 modality:FINAL visibility:public flags:data + GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp0_other_with_cast type:Test2 flags:val + TYPE_OP type=Test2 origin=CAST typeOperand=Test2 + typeOperand: CLASS CLASS name:Test2 modality:FINAL visibility:public flags:data + GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + arg1: CALL '(): T' type=T origin=GET_PROPERTY + $this: GET_VAR 'tmp0_other_with_cast: Test2' type=Test2 origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=true + CLASS CLASS name:Test3 modality:FINAL visibility:public flags:data + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test3 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + CONSTRUCTOR visibility:public <> (x:kotlin.collections.List) returnType:Test3 flags:primary + VALUE_PARAMETER name:x index:0 type:kotlin.collections.List flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Test3' + PROPERTY name:x type:kotlin.collections.List visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.collections.List visibility:public flags:final + EXPRESSION_BODY + GET_VAR 'value-parameter x: List' type=kotlin.collections.List origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test3) returnType:List flags: + correspondingProperty: PROPERTY name:x type:kotlin.collections.List visibility:public modality:FINAL flags:val + $this: VALUE_PARAMETER name: type:Test3 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): List' + GET_FIELD 'x: List' type=kotlin.collections.List origin=null + receiver: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:Test3) returnType:List flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='component1(): List' + CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:Test3, x:kotlin.collections.List) returnType:Test3 flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + VALUE_PARAMETER name:x index:0 type:kotlin.collections.List flags: + EXPRESSION_BODY + CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='copy(List = ...): Test3' + CALL 'constructor Test3(List)' type=Test3 origin=null + : T + x: GET_VAR 'value-parameter x: List = ...' type=kotlin.collections.List origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:Test3) returnType:String flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='toString(): String' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value=Test3( + CONST String type=kotlin.String value=x= + CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + CONST String type=kotlin.String value=) + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:Test3) returnType:Int flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + BLOCK_BODY + VAR IR_TEMPORARY_VARIABLE name:tmp0_result type:kotlin.Int flags:var + CONST Int type=kotlin.Int value=0 + SET_VAR 'tmp0_result: Int' type=kotlin.Unit origin=EQ + CALL 'hashCode(): Int' type=kotlin.Int origin=null + $this: CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + RETURN type=kotlin.Nothing from='hashCode(): Int' + GET_VAR 'tmp0_result: Int' type=kotlin.Int origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:Test3, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + BLOCK_BODY + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'EQEQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQEQ + arg0: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + arg1: GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=Test3 + typeOperand: CLASS CLASS name:Test3 modality:FINAL visibility:public flags:data + GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp0_other_with_cast type:Test3 flags:val + TYPE_OP type=Test3 origin=CAST typeOperand=Test3 + typeOperand: CLASS CLASS name:Test3 modality:FINAL visibility:public flags:data + GET_VAR 'value-parameter other: Any?' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + arg1: CALL '(): List' type=kotlin.collections.List origin=GET_PROPERTY + $this: GET_VAR 'tmp0_other_with_cast: Test3' type=Test3 origin=null + then: RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='equals(Any?): Boolean' + CONST Boolean type=kotlin.Boolean value=true diff --git a/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt index 9e1aa7d6bf9..e810dc6232f 100644 --- a/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt +++ b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt @@ -101,9 +101,7 @@ FILE fqName: fileName:/dataClassMembers.kt BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'hashCode(): Int' type=kotlin.Int origin=null - $this: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any - typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: - GET_VAR 'tmp1: T' type=T origin=null + $this: GET_VAR 'tmp1: T' type=T origin=null SET_VAR 'tmp0_result: Int' type=kotlin.Unit origin=EQ CALL 'plus(Int): Int' type=kotlin.Int origin=null $this: CALL 'times(Int): Int' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt new file mode 100644 index 00000000000..fa482951574 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt @@ -0,0 +1,15 @@ +fun test1(x: String?) = + if (x == null) 0 else x.length + +fun test2(x: T) = + if (x == null) 0 else x.length + +inline fun test3(x: Any) = + if (x !is T) 0 else x.length + +inline fun test4(x: Any?) = + if (x !is T) 0 else x.length + +fun test5(x: T, fn: (S) -> Unit) { + if (x != null) fn(x) +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.txt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.txt new file mode 100644 index 00000000000..2ae97dbee98 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.txt @@ -0,0 +1,89 @@ +FILE fqName: fileName:/implicitCastToNonNull.kt + FUN name:test1 visibility:public modality:FINAL <> (x:kotlin.String?) returnType:Int flags: + VALUE_PARAMETER name:x index:0 type:kotlin.String? flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='test1(String?): Int' + WHEN type=kotlin.Int origin=null + BRANCH + if: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'value-parameter x: String?' type=kotlin.String? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'value-parameter x: String?' type=kotlin.String? origin=null + FUN name:test2 visibility:public modality:FINAL (x:T) returnType:Int flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.CharSequence?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:CharSequence modality:ABSTRACT visibility:public flags: + VALUE_PARAMETER name:x index:0 type:T flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='test2(T): Int' + WHEN type=kotlin.Int origin=null + BRANCH + if: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'value-parameter x: T' type=T origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'value-parameter x: T' type=T origin=null + FUN name:test3 visibility:public modality:FINAL (x:kotlin.Any) returnType:Int flags:inline + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.CharSequence?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:CharSequence modality:ABSTRACT visibility:public flags: + VALUE_PARAMETER name:x index:0 type:kotlin.Any flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='test3(Any): Int' + WHEN type=kotlin.Int origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=T + typeOperand: TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.CharSequence?] + GET_VAR 'value-parameter x: Any' type=kotlin.Any origin=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY + $this: TYPE_OP type=kotlin.CharSequence origin=IMPLICIT_CAST typeOperand=kotlin.CharSequence + typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:CharSequence modality:ABSTRACT visibility:public flags: + GET_VAR 'value-parameter x: Any' type=kotlin.Any origin=null + FUN name:test4 visibility:public modality:FINAL (x:kotlin.Any?) returnType:Int flags:inline + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.CharSequence] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:CharSequence modality:ABSTRACT visibility:public flags: + VALUE_PARAMETER name:x index:0 type:kotlin.Any? flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='test4(Any?): Int' + WHEN type=kotlin.Int origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=T + typeOperand: TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.CharSequence] + GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY + $this: TYPE_OP type=kotlin.CharSequence origin=IMPLICIT_CAST typeOperand=kotlin.CharSequence + typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:CharSequence modality:ABSTRACT visibility:public flags: + GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null + FUN name:test5 visibility:public modality:FINAL (x:T, fn:(S) -> kotlin.Unit) returnType:Unit flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[S?] + superClassifiers: + TYPE_PARAMETER name:S index:1 variance: upperBounds:[kotlin.Any?] + TYPE_PARAMETER name:S index:1 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + VALUE_PARAMETER name:x index:0 type:T flags: + VALUE_PARAMETER name:fn index:1 type:(S) -> kotlin.Unit flags: + BLOCK_BODY + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_VAR 'value-parameter x: T' type=T origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CALL 'invoke(S): Unit' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'value-parameter fn: (S) -> Unit' type=(S) -> kotlin.Unit origin=VARIABLE_AS_FUNCTION + p1: GET_VAR 'value-parameter x: T' type=T origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 54ebc6a4365..b4238156213 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -867,6 +867,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.kt"); } + @TestMetadata("implicitCastToNonNull.kt") + public void testImplicitCastToNonNull() throws Exception { + runTest("compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt"); + } + @TestMetadata("implicitCastToTypeParameter.kt") public void testImplicitCastToTypeParameter() throws Exception { runTest("compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt");