FIR: Change the Fir2Ir handling of smart casts.

Generate the expression with the original type and then insert
an implicit conversion. That matches the behavior of psi2ir
better and therefore avoids breaking backend assumptions.

In particular, IrGetValue expects the type of the underlying
symbol and the type of the IrGetValue to be the same.
This commit is contained in:
Mads Ager
2020-01-30 11:25:06 +01:00
committed by max-kammerer
parent d68a1898d0
commit e8a640851a
48 changed files with 285 additions and 404 deletions
+14 -7
View File
@@ -28,7 +28,8 @@ FILE fqName:<root> fileName:/elvis.kt
then: GET_VAR 'b: kotlin.Any declared in <root>.test1' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.test1' type=kotlin.Any origin=null
then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.test1' type=kotlin.Any? origin=null
FUN name:test2 visibility:public modality:FINAL <> (a:kotlin.String?, b:kotlin.Any) returnType:kotlin.Any
VALUE_PARAMETER name:a index:0 type:kotlin.String?
VALUE_PARAMETER name:b index:1 type:kotlin.Any
@@ -45,7 +46,8 @@ FILE fqName:<root> fileName:/elvis.kt
then: GET_VAR 'b: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test2' type=kotlin.String origin=null
then: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test2' type=kotlin.String? origin=null
FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Any?, b:kotlin.Any?) returnType:kotlin.String
VALUE_PARAMETER name:a index:0 type:kotlin.Any?
VALUE_PARAMETER name:b index:1 type:kotlin.Any?
@@ -65,16 +67,19 @@ FILE fqName:<root> fileName:/elvis.kt
RETURN type=kotlin.Nothing from='public final fun test3 (a: kotlin.Any?, b: kotlin.Any?): kotlin.String declared in <root>'
BLOCK type=kotlin.String origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.String? [val]
GET_VAR 'a: kotlin.Any? declared in <root>.test3' type=kotlin.String? origin=null
TYPE_OP type=kotlin.String? origin=IMPLICIT_CAST typeOperand=kotlin.String?
GET_VAR 'a: kotlin.Any? declared in <root>.test3' type=kotlin.Any? origin=null
WHEN type=kotlin.String origin=ELVIS
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_2: kotlin.String? [val] declared in <root>.test3' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: GET_VAR 'b: kotlin.Any? declared in <root>.test3' type=kotlin.String origin=null
then: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR 'b: kotlin.Any? declared in <root>.test3' type=kotlin.Any? origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_2: kotlin.String? [val] declared in <root>.test3' type=kotlin.String origin=null
then: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR 'val tmp_2: kotlin.String? [val] declared in <root>.test3' type=kotlin.String? origin=null
FUN name:test4 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Any
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
@@ -90,7 +95,8 @@ FILE fqName:<root> fileName:/elvis.kt
then: GET_VAR 'x: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_3: kotlin.Any? [val] declared in <root>.test4' type=kotlin.Any origin=null
then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
GET_VAR 'val tmp_3: kotlin.Any? [val] declared in <root>.test4' type=kotlin.Any? origin=null
FUN name:test5 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Any
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
@@ -106,4 +112,5 @@ FILE fqName:<root> fileName:/elvis.kt
then: GET_VAR 'x: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_4: kotlin.Any? [val] declared in <root>.test5' type=kotlin.Any origin=null
then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
GET_VAR 'val tmp_4: kotlin.Any? [val] declared in <root>.test5' type=kotlin.Any? origin=null