psi2ir: fix nullability assertion generation for platform types

Incorporate PR from Steven Schäfer into IrType-based implicit cast
insertion (commit 17b925636e8717e7648c5d7b792c6ab4d18f776d).

NB this still uses originalKotlinType to determine if the type was
nullability flexible. It is somewhat error-prone and something we want
to get rid of. However, it boils down to some design questions related
to implicit null checks in Kotlin - e.g., it might be Ok to just treat
nullability flexible type `T!` as `T?` in IR, generate null checks for
all usages of type `T?` where a non-null type is expected, and later
eliminate the null checks that are redundant according to the (quite
conservative) criterion in the redundant null check elimination.
This commit is contained in:
Dmitry Petrov
2019-04-16 12:01:22 +03:00
parent ab38430ded
commit 1d9cb39915
14 changed files with 276 additions and 31 deletions
+4 -2
View File
@@ -36,7 +36,8 @@ FILE fqName:<root> fileName:/coercionToUnit.kt
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null
$this: GET_VAR 'val tmp0_safe_receiver: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
$this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream
GET_VAR 'val tmp0_safe_receiver: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
x: CONST String type=kotlin.String value="Hello,"
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
BLOCK type=kotlin.Unit? origin=SAFE_CALL
@@ -51,5 +52,6 @@ FILE fqName:<root> fileName:/coercionToUnit.kt
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null
$this: GET_VAR 'val tmp1_safe_receiver: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
$this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream
GET_VAR 'val tmp1_safe_receiver: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
x: CONST String type=kotlin.String value="world!"