Fix intersection type handling in PSI2IR

This commit is contained in:
Dmitry Petrov
2020-02-20 19:13:33 +03:00
parent 1624327ba4
commit e9a7be4a46
16 changed files with 463 additions and 76 deletions
@@ -1882,6 +1882,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/ir/irText/types/receiverOfIntersectionType.kt");
}
@TestMetadata("smartCastOnFakeOverrideReceiver.kt")
public void testSmartCastOnFakeOverrideReceiver() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.kt");
@@ -299,19 +299,19 @@ internal class InsertImplicitCasts(
null
private fun IrExpression.cast(
expectedType: KotlinType?,
originalExpectedType: KotlinType? = expectedType,
possiblyNonDenotableExpectedType: KotlinType?,
originalExpectedType: KotlinType? = possiblyNonDenotableExpectedType,
isLambdaReturnValue: Boolean = false
): IrExpression {
if (expectedType == null) return this
if (expectedType.isError) return this
if (possiblyNonDenotableExpectedType == null) return this
if (possiblyNonDenotableExpectedType.isError) return this
val expectedType = typeTranslator.approximate(possiblyNonDenotableExpectedType)
if (this is IrFunctionExpression && originalExpectedType != null) {
recordExpectedLambdaReturnTypeIfAppropriate(expectedType, originalExpectedType)
}
// TODO here we can have non-denotable KotlinTypes (both in 'this@cast.type' and 'expectedType').
val notNullableExpectedType = expectedType.makeNotNullable()
val valueType = this.type.originalKotlinType!!
@@ -62,27 +62,27 @@ class TypeTranslator(
}
fun translateType(kotlinType: KotlinType): IrType =
translateType(kotlinType, kotlinType, Variance.INVARIANT).type
translateType(kotlinType, Variance.INVARIANT).type
private fun translateType(kotlinType: KotlinType, approximatedKotlinType: KotlinType, variance: Variance): IrTypeProjection {
val approximatedType = LegacyTypeApproximation().approximate(kotlinType)
private fun translateType(kotlinType: KotlinType, variance: Variance): IrTypeProjection {
val flexibleApproximatedType = approximate(kotlinType)
when {
approximatedType.isError ->
return IrErrorTypeImpl(approximatedKotlinType, translateTypeAnnotations(approximatedType.annotations), variance)
approximatedType.isDynamic() ->
return IrDynamicTypeImpl(approximatedKotlinType, translateTypeAnnotations(approximatedType.annotations), variance)
approximatedType.isFlexible() ->
return translateType(approximatedType.upperIfFlexible(), approximatedType, variance)
flexibleApproximatedType.isError ->
return IrErrorTypeImpl(flexibleApproximatedType, translateTypeAnnotations(flexibleApproximatedType.annotations), variance)
flexibleApproximatedType.isDynamic() ->
return IrDynamicTypeImpl(flexibleApproximatedType, translateTypeAnnotations(flexibleApproximatedType.annotations), variance)
}
val approximatedType = flexibleApproximatedType.upperIfFlexible()
val ktTypeConstructor = approximatedType.constructor
val ktTypeDescriptor = ktTypeConstructor.declarationDescriptor
?: throw AssertionError("No descriptor for type $approximatedType")
return IrSimpleTypeBuilder().apply {
this.kotlinType = approximatedKotlinType
hasQuestionMark = approximatedType.isMarkedNullable
this.kotlinType = flexibleApproximatedType
this.hasQuestionMark = approximatedType.isMarkedNullable
this.variance = variance
this.abbreviation = approximatedType.getAbbreviation()?.toIrTypeAbbreviation()
when (ktTypeDescriptor) {
@@ -116,46 +116,42 @@ class TypeTranslator(
)
}
private inner class LegacyTypeApproximation {
fun approximate(ktType: KotlinType): KotlinType {
val properlyApproximatedType = approximateByKotlinRules(ktType)
fun approximate(ktType: KotlinType): KotlinType {
val properlyApproximatedType = approximateByKotlinRules(ktType)
// If there's an intersection type, take the most common supertype of its intermediate supertypes.
// That's what old back-end effectively does.
val typeConstructor = properlyApproximatedType.constructor
if (typeConstructor is IntersectionTypeConstructor) {
val commonSupertype = CommonSupertypes.commonSupertype(typeConstructor.supertypes)
return approximate(commonSupertype.replaceArgumentsWithStarProjections())
}
// Other types should be approximated properly. Right? Riiight?
return properlyApproximatedType
// If there's an intersection type, take the most common supertype of its intermediate supertypes.
// That's what old back-end effectively does.
val typeConstructor = properlyApproximatedType.constructor
if (typeConstructor is IntersectionTypeConstructor) {
val commonSupertype = CommonSupertypes.commonSupertype(typeConstructor.supertypes)
return approximate(commonSupertype.replaceArgumentsWithStarProjections())
}
private val isWithNewInference = languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
private fun approximateByKotlinRules(ktType: KotlinType): KotlinType =
if (isWithNewInference) {
if (ktType.constructor.isDenotable && ktType.arguments.isEmpty())
ktType
else
typeApproximatorForNI.approximateDeclarationType(
ktType,
local = false,
languageVersionSettings = languageVersionSettings
)
} else {
// Hack to preserve *-projections in arguments in OI.
// Expected to be removed as soon as OI is deprecated.
if (ktType.constructor.isDenotable)
ktType
else
approximateCapturedTypes(ktType).upper
}
// Assume that other types are approximated properly.
return properlyApproximatedType
}
private val isWithNewInference = languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
private fun approximateByKotlinRules(ktType: KotlinType): KotlinType =
if (isWithNewInference) {
if (ktType.constructor.isDenotable && ktType.arguments.isEmpty())
ktType
else
typeApproximatorForNI.approximateDeclarationType(
ktType,
local = false,
languageVersionSettings = languageVersionSettings
)
} else {
// Hack to preserve *-projections in arguments in OI.
// Expected to be removed as soon as OI is deprecated.
if (ktType.constructor.isDenotable)
ktType
else
approximateCapturedTypes(ktType).upper
}
private fun translateTypeAnnotations(annotations: Annotations): List<IrConstructorCall> =
annotations.mapNotNull(constantValueGenerator::generateAnnotationConstructorCall)
@@ -164,6 +160,6 @@ class TypeTranslator(
if (it.isStarProjection)
IrStarProjectionImpl
else
translateType(it.type, it.type, it.projectionKind)
translateType(it.type, it.projectionKind)
}
}
@@ -0,0 +1,20 @@
interface K
interface I : K {
fun ff(): String
}
interface J : K {}
class A: I, J {
override fun ff() = "OK"
}
class B: I, J {
override fun ff() = "Irrelevant"
}
fun box(): String {
val v = if (true) A() else B()
return v.ff()
}
@@ -36,15 +36,15 @@ FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
$receiver: VALUE_PARAMETER name:<this> type:<root>.Foo<T of <root>.<get-asT>>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-asT> <T> (): T of <root>.<get-asT>? [inline] declared in <root>'
WHEN type=kotlin.Any? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <root>.<get-asT>
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
TYPE_OP type=T of <root>.<get-asT>? origin=IMPLICIT_CAST typeOperand=T of <root>.<get-asT>?
WHEN type=kotlin.Any? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <root>.<get-asT>
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
then: GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Bar<T of <root>.Bar>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
@@ -95,19 +95,21 @@ FILE fqName:<root> fileName:/localVariableOfIntersectionType_NI.kt
VALUE_PARAMETER name:z index:2 type:<root>.Z
BLOCK_BODY
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.IA' type=kotlin.Unit origin=null
$this: CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
$this: TYPE_OP type=<root>.IA origin=IMPLICIT_CAST typeOperand=<root>.IA
CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
CALL 'public abstract fun bar (): kotlin.Unit declared in <root>.IB' type=kotlin.Unit origin=null
$this: CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
$this: TYPE_OP type=<root>.IB origin=IMPLICIT_CAST typeOperand=<root>.IB
CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
VAR name:t type:kotlin.Any [val]
CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
@@ -116,6 +118,8 @@ FILE fqName:<root> fileName:/localVariableOfIntersectionType_NI.kt
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.IA' type=kotlin.Unit origin=null
$this: GET_VAR 'val t: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
$this: TYPE_OP type=<root>.IA origin=IMPLICIT_CAST typeOperand=<root>.IA
GET_VAR 'val t: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
CALL 'public abstract fun bar (): kotlin.Unit declared in <root>.IB' type=kotlin.Unit origin=null
$this: GET_VAR 'val t: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
$this: TYPE_OP type=<root>.IB origin=IMPLICIT_CAST typeOperand=<root>.IB
GET_VAR 'val t: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
@@ -0,0 +1,136 @@
FILE fqName:<root> fileName:/receiverOfIntersectionType.kt
CLASS INTERFACE name:K modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.K
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 INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[<root>.K]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.I
FUN name:ff visibility:public modality:ABSTRACT <> ($this:<root>.I) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.I
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 INTERFACE name:J modality:ABSTRACT visibility:public superTypes:[<root>.K]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.J
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:A modality:FINAL visibility:public superTypes:[<root>.I; <root>.J]
$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:FINAL visibility:public superTypes:[<root>.I; <root>.J]'
FUN name:ff visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
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>.I; <root>.J]
$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 kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.I; <root>.J]'
FUN name:ff visibility:public modality:FINAL <> ($this:<root>.B) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.B
BLOCK_BODY
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
FUN name:testIntersection visibility:public modality:FINAL <> (a:<root>.A, b:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.A
VALUE_PARAMETER name:b index:1 type:<root>.B
BLOCK_BODY
VAR name:v type:<root>.I [val]
WHEN type=<root>.I origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'a: <root>.A declared in <root>.testIntersection' type=<root>.A origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'b: <root>.B declared in <root>.testIntersection' type=<root>.B origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: GET_VAR 'val v: <root>.I [val] declared in <root>.testIntersection' type=<root>.I origin=null
FUN name:testFlexible1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:v type:<root>.I? [val]
WHEN type=<root>.I? origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun a (): <root>.A? declared in <root>.Java' type=<root>.A? origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun b (): <root>.B? declared in <root>.Java' type=<root>.B? origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: GET_VAR 'val v: <root>.I? [val] declared in <root>.testFlexible1' type=<root>.I? origin=null
FUN name:testFlexible2 visibility:public modality:FINAL <> (a:<root>.A, b:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.A
VALUE_PARAMETER name:b index:1 type:<root>.B
BLOCK_BODY
VAR name:v type:<root>.I? [val]
WHEN type=<root>.I? origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun id <T> (x: T of <root>.Java.id?): T of <root>.Java.id? declared in <root>.Java' type=<root>.A? origin=null
<T>: <root>.A?
x: GET_VAR 'a: <root>.A declared in <root>.testFlexible2' type=<root>.A origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun id <T> (x: T of <root>.Java.id?): T of <root>.Java.id? declared in <root>.Java' type=<root>.B? origin=null
<T>: <root>.B?
x: GET_VAR 'b: <root>.B declared in <root>.testFlexible2' type=<root>.B origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: GET_VAR 'val v: <root>.I? [val] declared in <root>.testFlexible2' type=<root>.I? origin=null
@@ -0,0 +1,40 @@
// !LANGUAGE: +NewInference
// FILE: receiverOfIntersectionType.kt
interface K
interface I : K {
fun ff()
}
interface J : K {}
class A: I, J {
override fun ff() {}
}
class B: I, J {
override fun ff() {}
}
fun testIntersection(a: A, b: B) {
val v = if (true) a else b
v.ff()
}
fun testFlexible1() {
val v = if (true) Java.a() else Java.b()
v.ff()
}
fun testFlexible2(a: A, b: B) {
val v = if (true) Java.id(a) else Java.id(b)
v.ff()
}
// FILE: Java.java
public class Java {
public static A a() { return new A(); }
public static B b() { return new B(); }
public static <T> T id(T x) { return x; }
}
@@ -0,0 +1,151 @@
FILE fqName:<root> fileName:/receiverOfIntersectionType.kt
CLASS INTERFACE name:K modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.K
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 INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[<root>.K]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.I
FUN name:ff visibility:public modality:ABSTRACT <> ($this:<root>.I) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.I
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>.K
$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>.K
$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>.K
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS INTERFACE name:J modality:ABSTRACT visibility:public superTypes:[<root>.K]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.J
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>.K
$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>.K
$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>.K
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:A modality:FINAL visibility:public superTypes:[<root>.I; <root>.J]
$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:FINAL visibility:public superTypes:[<root>.I; <root>.J]'
FUN name:ff visibility:public modality:OPEN <> ($this:<root>.A) returnType:kotlin.Unit
overridden:
public abstract fun ff (): kotlin.Unit declared in <root>.I
$this: VALUE_PARAMETER name:<this> type:<root>.A
BLOCK_BODY
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>.I
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.J
$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>.I
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.J
$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>.I
public open fun toString (): kotlin.String [fake_override] declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.I; <root>.J]
$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 kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.I; <root>.J]'
FUN name:ff visibility:public modality:OPEN <> ($this:<root>.B) returnType:kotlin.Unit
overridden:
public abstract fun ff (): kotlin.Unit declared in <root>.I
$this: VALUE_PARAMETER name:<this> type:<root>.B
BLOCK_BODY
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>.I
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.J
$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>.I
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.J
$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>.I
public open fun toString (): kotlin.String [fake_override] declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:testIntersection visibility:public modality:FINAL <> (a:<root>.A, b:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.A
VALUE_PARAMETER name:b index:1 type:<root>.B
BLOCK_BODY
VAR name:v type:<root>.K [val]
WHEN type=<root>.K origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'a: <root>.A declared in <root>.testIntersection' type=<root>.A origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'b: <root>.B declared in <root>.testIntersection' type=<root>.B origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.I origin=IMPLICIT_CAST typeOperand=<root>.I
GET_VAR 'val v: <root>.K [val] declared in <root>.testIntersection' type=<root>.K origin=null
FUN name:testFlexible1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:v type:<root>.K? [val]
WHEN type=<root>.K? origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun a (): <root>.A? declared in <root>.Java' type=<root>.A? origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun b (): <root>.B? declared in <root>.Java' type=<root>.B? origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.I origin=IMPLICIT_CAST typeOperand=<root>.I
TYPE_OP type=<root>.K origin=IMPLICIT_NOTNULL typeOperand=<root>.K
GET_VAR 'val v: <root>.K? [val] declared in <root>.testFlexible1' type=<root>.K? origin=null
FUN name:testFlexible2 visibility:public modality:FINAL <> (a:<root>.A, b:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.A
VALUE_PARAMETER name:b index:1 type:<root>.B
BLOCK_BODY
VAR name:v type:<root>.K? [val]
WHEN type=<root>.K? origin=IF
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun id <T> (x: T of <root>.Java.id?): T of <root>.Java.id? declared in <root>.Java' type=<root>.A? origin=null
<T>: <root>.A?
x: GET_VAR 'a: <root>.A declared in <root>.testFlexible2' type=<root>.A origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun id <T> (x: T of <root>.Java.id?): T of <root>.Java.id? declared in <root>.Java' type=<root>.B? origin=null
<T>: <root>.B?
x: GET_VAR 'b: <root>.B declared in <root>.testFlexible2' type=<root>.B origin=null
CALL 'public abstract fun ff (): kotlin.Unit declared in <root>.I' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.I origin=IMPLICIT_CAST typeOperand=<root>.I
TYPE_OP type=<root>.K origin=IMPLICIT_NOTNULL typeOperand=<root>.K
GET_VAR 'val v: <root>.K? [val] declared in <root>.testFlexible2' type=<root>.K? origin=null
@@ -28255,6 +28255,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -27072,6 +27072,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -26754,6 +26754,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -26754,6 +26754,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -1881,6 +1881,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/ir/irText/types/receiverOfIntersectionType.kt");
}
@TestMetadata("smartCastOnFakeOverrideReceiver.kt")
public void testSmartCastOnFakeOverrideReceiver() throws Exception {
runTest("compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.kt");
@@ -21740,6 +21740,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -21800,6 +21800,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/traits/privateInterfaceMethod.kt");
}
@TestMetadata("receiverOfIntersectionType.kt")
public void testReceiverOfIntersectionType() throws Exception {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");