[FIR2IR] Make safe call result always nullable
This commit is contained in:
@@ -389,7 +389,7 @@ fun Fir2IrComponents.createSafeCallConstruction(
|
||||
val startOffset = expressionOnNotNull.startOffset
|
||||
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 {
|
||||
statements += receiverVariable
|
||||
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`.
|
||||
|
||||
public class StockMarketTableModel() {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun test(s: String) = s?.length
|
||||
|
||||
// 0 IFNULL
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// !API_VERSION: LATEST
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
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
|
||||
BLOCK_BODY
|
||||
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]
|
||||
CONST Int type=kotlin.Int value=42
|
||||
WHEN type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Int? 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
|
||||
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