[FIR2IR] Make safe call result always nullable
This commit is contained in:
@@ -389,7 +389,7 @@ fun Fir2IrComponents.createSafeCallConstruction(
|
|||||||
val startOffset = expressionOnNotNull.startOffset
|
val startOffset = expressionOnNotNull.startOffset
|
||||||
val endOffset = expressionOnNotNull.endOffset
|
val endOffset = expressionOnNotNull.endOffset
|
||||||
|
|
||||||
val resultType = expressionOnNotNull.type.let { if (isReceiverNullable) it.makeNullable() else it }
|
val resultType = expressionOnNotNull.type.makeNullable()
|
||||||
return IrBlockImpl(startOffset, endOffset, resultType, IrStatementOrigin.SAFE_CALL).apply {
|
return IrBlockImpl(startOffset, endOffset, resultType, IrStatementOrigin.SAFE_CALL).apply {
|
||||||
statements += receiverVariable
|
statements += receiverVariable
|
||||||
statements += IrWhenImpl(startOffset, endOffset, resultType).apply {
|
statements += IrWhenImpl(startOffset, endOffset, resultType).apply {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// The IR prduced by FIR implicitly casts `null` of type `Nothing?` to type `Int` instead of `Int?` in `getColumnCount`.
|
// The IR prduced by FIR implicitly casts `null` of type `Nothing?` to type `Int` instead of `Int?` in `getColumnCount`.
|
||||||
|
|
||||||
public class StockMarketTableModel() {
|
public class StockMarketTableModel() {
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
fun test(s: String) = s?.length
|
fun test(s: String) = s?.length
|
||||||
|
|
||||||
// 0 IFNULL
|
// 0 IFNULL
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !API_VERSION: LATEST
|
// !API_VERSION: LATEST
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
fun test(s: String) = s?.length
|
fun test(s: String) = s?.length
|
||||||
|
|
||||||
|
|||||||
@@ -158,10 +158,10 @@ FILE fqName:<root> fileName:/safeCalls.kt
|
|||||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||||
BLOCK type=kotlin.Int origin=SAFE_CALL
|
BLOCK type=kotlin.Int? origin=SAFE_CALL
|
||||||
VAR IR_TEMPORARY_VARIABLE name:tmp_5 type:kotlin.Int [val]
|
VAR IR_TEMPORARY_VARIABLE name:tmp_5 type:kotlin.Int [val]
|
||||||
CONST Int type=kotlin.Int value=42
|
CONST Int type=kotlin.Int value=42
|
||||||
WHEN type=kotlin.Int origin=null
|
WHEN type=kotlin.Int? origin=null
|
||||||
BRANCH
|
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
|
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||||
arg0: GET_VAR 'val tmp_5: kotlin.Int [val] declared in <root>.box' type=kotlin.Int origin=null
|
arg0: GET_VAR 'val tmp_5: kotlin.Int [val] declared in <root>.box' type=kotlin.Int origin=null
|
||||||
|
|||||||
Reference in New Issue
Block a user