FIR2IR: standardize expression with smart cast conversion
To convert smart cast expression, now we just convert original expression in standard way and wrap it with TYPE_OP. Before this commit original expression was converted in different way, that led to errors e.g. for this expression casting.
This commit is contained in:
@@ -936,7 +936,7 @@ class Fir2IrVisitor(
|
|||||||
|
|
||||||
override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: Any?): IrElement {
|
override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: Any?): IrElement {
|
||||||
// Generate the expression with the original type and then cast it to the smart cast type.
|
// Generate the expression with the original type and then cast it to the smart cast type.
|
||||||
val value = expressionWithSmartcast.toIrExpression(expressionWithSmartcast.originalType).applyReceivers(expressionWithSmartcast)
|
val value = expressionWithSmartcast.originalExpression.toIrExpression()
|
||||||
val castType = expressionWithSmartcast.typeRef.toIrType(session, declarationStorage)
|
val castType = expressionWithSmartcast.typeRef.toIrType(session, declarationStorage)
|
||||||
if (value.type == castType) return value
|
if (value.type == castType) return value
|
||||||
return IrTypeOperatorCallImpl(
|
return IrTypeOperatorCallImpl(
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// JVM_TARGET: 1.8
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
abstract class C {
|
abstract class C {
|
||||||
fun test(x: Int) {
|
fun test(x: Int) {
|
||||||
if (x == 0) return
|
if (x == 0) return
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class SuperFoo {
|
open class SuperFoo {
|
||||||
public fun bar(): String {
|
public fun bar(): String {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class A {
|
open class A {
|
||||||
class B : A() {
|
class B : A() {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class A {
|
open class A {
|
||||||
fun f(): String =
|
fun f(): String =
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class A {
|
open class A {
|
||||||
open fun foo() = "FAIL"
|
open fun foo() = "FAIL"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
open class Test1 {
|
open class Test1 {
|
||||||
fun test1(): String {
|
fun test1(): String {
|
||||||
if (this is Test2) {
|
if (this is Test2) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
package h
|
package h
|
||||||
|
|
||||||
open class A {
|
open class A {
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ FILE fqName:<root> fileName:/localDelegatedProperties.kt
|
|||||||
GET_VAR 'val tmp_0: kotlin.Int [val] declared in <root>.test2' type=kotlin.Int origin=null
|
GET_VAR 'val tmp_0: kotlin.Int [val] declared in <root>.test2' type=kotlin.Int origin=null
|
||||||
SET_VAR 'var x: IrErrorType [var] declared in <root>.test2' type=kotlin.Unit origin=null
|
SET_VAR 'var x: IrErrorType [var] declared in <root>.test2' type=kotlin.Unit origin=null
|
||||||
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
|
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
|
||||||
$this: GET_VAR 'var x: IrErrorType [var] declared in <root>.test2' type=kotlin.Int origin=null
|
$this: TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
|
||||||
|
GET_VAR 'var x: IrErrorType [var] declared in <root>.test2' type=IrErrorType origin=null
|
||||||
other: CONST Int type=kotlin.Int value=1
|
other: CONST Int type=kotlin.Int value=1
|
||||||
|
|||||||
+2
-1
@@ -87,7 +87,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
|||||||
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
|
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
|
||||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
|
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
|
||||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function0<kotlin.Unit> origin=null
|
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function0<kotlin.Unit>
|
||||||
|
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||||
FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ FILE fqName:<root> fileName:/smartCastOnReceiverOfGenericType.kt
|
|||||||
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
|
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
|
||||||
GET_VAR 'c: kotlin.Any declared in <root>.testInnerClass' type=kotlin.Any origin=null
|
GET_VAR 'c: kotlin.Any declared in <root>.testInnerClass' type=kotlin.Any origin=null
|
||||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/Outer.Inner.use]>#' type=IrErrorType
|
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/Outer.Inner.use]>#' type=IrErrorType
|
||||||
GET_VAR 'b: kotlin.Any declared in <root>.testInnerClass' type=kotlin.Int origin=null
|
TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
|
||||||
GET_VAR 'c: kotlin.Any declared in <root>.testInnerClass' type=kotlin.String origin=null
|
GET_VAR 'b: kotlin.Any declared in <root>.testInnerClass' type=kotlin.Any origin=null
|
||||||
|
TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
|
||||||
|
GET_VAR 'c: kotlin.Any declared in <root>.testInnerClass' type=kotlin.Any origin=null
|
||||||
FUN name:testNonSubstitutedTypeParameter visibility:public modality:FINAL <T> (a:kotlin.Any, b:kotlin.Any) returnType:kotlin.Unit
|
FUN name:testNonSubstitutedTypeParameter visibility:public modality:FINAL <T> (a:kotlin.Any, b:kotlin.Any) returnType:kotlin.Unit
|
||||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||||
VALUE_PARAMETER name:a index:0 type:kotlin.Any
|
VALUE_PARAMETER name:a index:0 type:kotlin.Any
|
||||||
|
|||||||
Reference in New Issue
Block a user