PSI2IR: Infer smart cast on dispatch receiver of FAKE_OVERRIDE calls

NB here we have use derived class type with type arguments replaced
with star-projections. This emulates JVM erasure (to some degree),
but, unfortunately, that's best we can offer here at the moment.
This commit is contained in:
Dmitry Petrov
2019-12-18 16:04:11 +03:00
parent feda832eb7
commit 09c3279cc7
8 changed files with 493 additions and 8 deletions
@@ -1740,6 +1740,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/types/platformTypeReceiver.kt");
}
@TestMetadata("smartCastOnFakeOverrideReceiver.kt")
public void testSmartCastOnFakeOverrideReceiver() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.kt");
}
@TestMetadata("smartCastOnFieldReceiverOfGenericType.kt")
public void testSmartCastOnFieldReceiverOfGenericType() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.kt");
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.psi2ir.transformations
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrClass
@@ -38,10 +40,7 @@ import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.isNullableAny
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.types.typeUtil.*
fun insertImplicitCasts(element: IrElement, context: GeneratorContext) {
element.transformChildren(
@@ -77,10 +76,27 @@ open class InsertImplicitCasts(
}
private fun IrMemberAccessExpression.transformReceiverArguments(substitutedDescriptor: CallableDescriptor) {
dispatchReceiver = dispatchReceiver?.cast(substitutedDescriptor.dispatchReceiverParameter?.type)
dispatchReceiver = dispatchReceiver?.cast(getEffectiveDispatchReceiverType(substitutedDescriptor))
extensionReceiver = extensionReceiver?.cast(substitutedDescriptor.extensionReceiverParameter?.type)
}
private fun getEffectiveDispatchReceiverType(descriptor: CallableDescriptor): KotlinType? =
when {
descriptor !is CallableMemberDescriptor ->
null
descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE -> {
val containingDeclaration = descriptor.containingDeclaration
if (containingDeclaration !is ClassDescriptor)
throw AssertionError("Containing declaration for $descriptor should be a class: $containingDeclaration")
else
containingDeclaration.defaultType.replaceArgumentsWithStarProjections()
}
else ->
descriptor.dispatchReceiverParameter?.type
}
override fun visitMemberAccess(expression: IrMemberAccessExpression): IrExpression {
val substitutedDescriptor = expression.substitutedDescriptor
return expression.transformPostfix {
@@ -132,8 +148,14 @@ open class InsertImplicitCasts(
value = value.cast(expression.symbol.descriptor.type)
}
override fun visitGetField(expression: IrGetField): IrExpression =
expression.transformPostfix {
receiver = receiver?.cast(getEffectiveDispatchReceiverType(expression.symbol.descriptor))
}
override fun visitSetField(expression: IrSetField): IrExpression =
expression.transformPostfix {
receiver = receiver?.cast(getEffectiveDispatchReceiverType(expression.symbol.descriptor))
value = value.cast(expression.symbol.descriptor.type)
}
-1
View File
@@ -1,5 +1,4 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -0,0 +1,209 @@
FILE fqName:<root> fileName:/smartCastOnFakeOverrideReceiver.kt
CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
CONSTRUCTOR visibility:public <> () returnType:<root>.A [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any]'
FUN name:f visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in <root>.A'
CONST Int type=kotlin.Int value=1
PROPERTY name:aVal visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
CONST Int type=kotlin.Int value=42
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int
correspondingProperty: PROPERTY name:aVal visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-aVal> (): kotlin.Int declared in <root>.A'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.A declared in <root>.A.<get-aVal>' type=<root>.A origin=null
FUN name:testA1 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testA1 (x: kotlin.Any): kotlin.Int? declared in <root>.A'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA1' type=kotlin.Any origin=null
then: CALL 'public final fun f (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
$this: GET_VAR 'x: kotlin.Any declared in <root>.A.testA1' type=<root>.B origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN name:testA2 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testA2 (x: kotlin.Any): kotlin.Int? declared in <root>.A'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA2' type=kotlin.Any origin=null
then: CALL 'public final fun <get-aVal> (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
$this: GET_VAR 'x: kotlin.Any declared in <root>.A.testA2' type=<root>.B origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
CONSTRUCTOR visibility:public <> () returnType:<root>.B [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.A'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A]'
FUN name:testB1 visibility:public modality:FINAL <> ($this:<root>.B, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.B
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testB1 (x: kotlin.Any): kotlin.Int? declared in <root>.B'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB1' type=kotlin.Any origin=null
then: CALL 'public final fun f (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
$this: GET_VAR 'x: kotlin.Any declared in <root>.B.testB1' type=<root>.B origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN name:testB2 visibility:public modality:FINAL <> ($this:<root>.B, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.B
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testB2 (x: kotlin.Any): kotlin.Int? declared in <root>.B'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB2' type=kotlin.Any origin=null
then: CALL 'public final fun <get-aVal> (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
$this: GET_VAR 'x: kotlin.Any declared in <root>.B.testB2' type=<root>.B origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN FAKE_OVERRIDE name:f visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int [fake_override]
overridden:
public final fun f (): kotlin.Int declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
FUN FAKE_OVERRIDE name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.B) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-aVal> (): kotlin.Int declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.B
FUN FAKE_OVERRIDE name:testA1 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int? [fake_override]
overridden:
public final fun testA1 (x: kotlin.Any): kotlin.Int? declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
FUN FAKE_OVERRIDE name:testA2 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int? [fake_override]
overridden:
public final fun testA2 (x: kotlin.Any): kotlin.Int? declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:GA modality:OPEN visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.GA
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.GA<T of <root>.GA> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GA modality:OPEN visibility:public superTypes:[kotlin.Any]'
FUN name:f visibility:public modality:FINAL <> ($this:<root>.GA) returnType:kotlin.Int
$this: VALUE_PARAMETER name:<this> type:<root>.GA
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in <root>.GA'
CONST Int type=kotlin.Int value=1
PROPERTY name:aVal visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
CONST Int type=kotlin.Int value=42
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.GA) returnType:kotlin.Int
correspondingProperty: PROPERTY name:aVal visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.GA
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-aVal> (): kotlin.Int declared in <root>.GA'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.GA declared in <root>.GA.<get-aVal>' type=<root>.GA origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.GB
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:S index:1 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.GB<T of <root>.GB, S of <root>.GB> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.GA'
<T>: <none>
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]'
FUN name:testGB1 visibility:public modality:FINAL <> ($this:<root>.GB, a:kotlin.Any) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.GB
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=<root>.GB<kotlin.Int, kotlin.String> origin=CAST typeOperand=<root>.GB<kotlin.Int, kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=kotlin.Any origin=null
CALL 'public final fun f (): kotlin.Int declared in <root>.GA' type=kotlin.Int origin=null
$this: GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=<root>.GB<kotlin.Int, kotlin.String> origin=null
CALL 'public final fun <get-aVal> (): kotlin.Int declared in <root>.GA' type=kotlin.Int origin=null
$this: GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=<root>.GB<kotlin.Int, kotlin.String> origin=null
FUN FAKE_OVERRIDE name:f visibility:public modality:FINAL <> ($this:<root>.GA) returnType:kotlin.Int [fake_override]
overridden:
public final fun f (): kotlin.Int declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:<root>.GA
PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
FUN FAKE_OVERRIDE name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.GB) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-aVal> (): kotlin.Int declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:<root>.GB
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,25 @@
open class A {
fun f() = 1
val aVal = 42
fun testA1(x: Any) = if (x is B) x.f() else null
fun testA2(x: Any) = if (x is B) x.aVal else null
}
class B : A() {
fun testB1(x: Any) = if (x is B) x.f() else null
fun testB2(x: Any) = if (x is B) x.aVal else null
}
open class GA<T> {
fun f() = 1
val aVal = 42
}
class GB<T, S> : GA<T>() {
fun testGB1(a: Any) {
a as GB<Int, String>
a.f()
a.aVal
}
}
@@ -0,0 +1,218 @@
FILE fqName:<root> fileName:/smartCastOnFakeOverrideReceiver.kt
CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
CONSTRUCTOR visibility:public <> () returnType:<root>.A [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any]'
FUN name:f visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in <root>.A'
CONST Int type=kotlin.Int value=1
PROPERTY name:aVal visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
CONST Int type=kotlin.Int value=42
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int
correspondingProperty: PROPERTY name:aVal visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-aVal> (): kotlin.Int declared in <root>.A'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.A declared in <root>.A.<get-aVal>' type=<root>.A origin=null
FUN name:testA1 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testA1 (x: kotlin.Any): kotlin.Int? declared in <root>.A'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA1' type=kotlin.Any origin=null
then: CALL 'public final fun f (): kotlin.Int [fake_override] declared in <root>.B' type=kotlin.Int origin=null
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA1' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN name:testA2 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testA2 (x: kotlin.Any): kotlin.Int? declared in <root>.A'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA2' type=kotlin.Any origin=null
then: CALL 'public final fun <get-aVal> (): kotlin.Int [fake_override] declared in <root>.B' type=kotlin.Int origin=GET_PROPERTY
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.A.testA2' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
CONSTRUCTOR visibility:public <> () returnType:<root>.B [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.A'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A]'
FUN name:testB1 visibility:public modality:FINAL <> ($this:<root>.B, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.B
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testB1 (x: kotlin.Any): kotlin.Int? declared in <root>.B'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB1' type=kotlin.Any origin=null
then: CALL 'public final fun f (): kotlin.Int [fake_override] declared in <root>.B' type=kotlin.Int origin=null
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB1' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN name:testB2 visibility:public modality:FINAL <> ($this:<root>.B, x:kotlin.Any) returnType:kotlin.Int?
$this: VALUE_PARAMETER name:<this> type:<root>.B
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testB2 (x: kotlin.Any): kotlin.Int? declared in <root>.B'
WHEN type=kotlin.Int? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB2' type=kotlin.Any origin=null
then: CALL 'public final fun <get-aVal> (): kotlin.Int [fake_override] declared in <root>.B' type=kotlin.Int origin=GET_PROPERTY
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
GET_VAR 'x: kotlin.Any declared in <root>.B.testB2' type=kotlin.Any origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
FUN FAKE_OVERRIDE name:f visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int [fake_override]
overridden:
public final fun f (): kotlin.Int declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
FUN FAKE_OVERRIDE name:testA1 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int? [fake_override]
overridden:
public final fun testA1 (x: kotlin.Any): kotlin.Int? declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
FUN FAKE_OVERRIDE name:testA2 visibility:public modality:FINAL <> ($this:<root>.A, x:kotlin.Any) returnType:kotlin.Int? [fake_override]
overridden:
public final fun testA2 (x: kotlin.Any): kotlin.Int? declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
VALUE_PARAMETER name:x index:0 type:kotlin.Any
PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
FUN FAKE_OVERRIDE name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-aVal> (): kotlin.Int declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:<root>.A
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:GA modality:OPEN visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.GA<T of <root>.GA>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.GA<T of <root>.GA> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GA modality:OPEN visibility:public superTypes:[kotlin.Any]'
FUN name:f visibility:public modality:FINAL <> ($this:<root>.GA<T of <root>.GA>) returnType:kotlin.Int
$this: VALUE_PARAMETER name:<this> type:<root>.GA<T of <root>.GA>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in <root>.GA'
CONST Int type=kotlin.Int value=1
PROPERTY name:aVal visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
CONST Int type=kotlin.Int value=42
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.GA<T of <root>.GA>) returnType:kotlin.Int
correspondingProperty: PROPERTY name:aVal visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.GA<T of <root>.GA>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-aVal> (): kotlin.Int declared in <root>.GA'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aVal type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.GA<T of <root>.GA> declared in <root>.GA.<get-aVal>' type=<root>.GA<T of <root>.GA> origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.GB<T of <root>.GB, S of <root>.GB>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:S index:1 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.GB<T of <root>.GB, S of <root>.GB> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.GA'
<T>: T of <root>.GB
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]'
FUN name:testGB1 visibility:public modality:FINAL <> ($this:<root>.GB<T of <root>.GB, S of <root>.GB>, a:kotlin.Any) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.GB<T of <root>.GB, S of <root>.GB>
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=<root>.GB<kotlin.Int, kotlin.String> origin=CAST typeOperand=<root>.GB<kotlin.Int, kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=kotlin.Any origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public final fun f (): kotlin.Int [fake_override] declared in <root>.GB' type=kotlin.Int origin=null
$this: TYPE_OP type=<root>.GB<*, *> origin=IMPLICIT_CAST typeOperand=<root>.GB<*, *>
GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=kotlin.Any origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public final fun <get-aVal> (): kotlin.Int [fake_override] declared in <root>.GB' type=kotlin.Int origin=GET_PROPERTY
$this: TYPE_OP type=<root>.GB<*, *> origin=IMPLICIT_CAST typeOperand=<root>.GB<*, *>
GET_VAR 'a: kotlin.Any declared in <root>.GB.testGB1' type=kotlin.Any origin=null
FUN FAKE_OVERRIDE name:f visibility:public modality:FINAL <> ($this:<root>.GA<T of <root>.GB>) returnType:kotlin.Int [fake_override]
overridden:
public final fun f (): kotlin.Int declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:<root>.GA<T of <root>.GB>
PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
FUN FAKE_OVERRIDE name:<get-aVal> visibility:public modality:FINAL <> ($this:<root>.GA<T of <root>.GB>) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:aVal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-aVal> (): kotlin.Int declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:<root>.GA<T of <root>.GB>
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.GA
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -10,7 +10,8 @@ FILE fqName:<root> fileName:/smartCastOnFieldReceiverOfGenericType.kt
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
GET_VAR 'b: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of <root>.JCell? visibility:public' type=kotlin.Unit origin=EQ
receiver: GET_VAR 'a: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
receiver: TYPE_OP type=<root>.JCell<T of <root>.JCell> origin=IMPLICIT_CAST typeOperand=<root>.JCell<T of <root>.JCell>
GET_VAR 'a: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
value: TYPE_OP type=T of <root>.JCell origin=IMPLICIT_CAST typeOperand=T of <root>.JCell
GET_VAR 'b: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
FUN name:testGetField visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.String
@@ -22,4 +23,5 @@ FILE fqName:<root> fileName:/smartCastOnFieldReceiverOfGenericType.kt
RETURN type=kotlin.Nothing from='public final fun testGetField (a: kotlin.Any): kotlin.String declared in <root>'
TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of <root>.JCell? visibility:public' type=kotlin.String? origin=GET_PROPERTY
receiver: GET_VAR 'a: kotlin.Any declared in <root>.testGetField' type=kotlin.Any origin=null
receiver: TYPE_OP type=<root>.JCell<T of <root>.JCell> origin=IMPLICIT_CAST typeOperand=<root>.JCell<T of <root>.JCell>
GET_VAR 'a: kotlin.Any declared in <root>.testGetField' type=kotlin.Any origin=null
@@ -1740,6 +1740,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/types/platformTypeReceiver.kt");
}
@TestMetadata("smartCastOnFakeOverrideReceiver.kt")
public void testSmartCastOnFakeOverrideReceiver() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.kt");
}
@TestMetadata("smartCastOnFieldReceiverOfGenericType.kt")
public void testSmartCastOnFieldReceiverOfGenericType() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFieldReceiverOfGenericType.kt");