[FIR2IR] Support (simple) conversion of captured types

This commit is contained in:
Mikhail Glukhikh
2020-03-12 12:15:11 +03:00
parent e919e7b79a
commit 6fd8ccc293
7 changed files with 225 additions and 2 deletions
@@ -62,7 +62,9 @@ class Fir2IrTypeConverter(
// TODO: yet we take more general type. Not quite sure it's Ok
upperBound.toIrType(typeContext)
}
is ConeCapturedType -> TODO()
is ConeCapturedType -> {
lowerType?.toIrType(typeContext) ?: constructor.supertypes!!.first().toIrType(typeContext)
}
is ConeDefinitelyNotNullType -> {
original.toIrType(typeContext.definitelyNotNull())
}
@@ -1872,6 +1872,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/types/coercionToUnitInLambdaReturnValue.kt");
}
@TestMetadata("genericFunWithStar.kt")
public void testGenericFunWithStar() throws Exception {
runTest("compiler/testData/ir/irText/types/genericFunWithStar.kt");
}
@TestMetadata("genericPropertyReferenceType.kt")
public void testGenericPropertyReferenceType() throws Exception {
runTest("compiler/testData/ir/irText/types/genericPropertyReferenceType.kt");
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun test(i: Inv<out Any?>) {
foo(i.superclass())
}
@@ -0,0 +1,97 @@
FILE fqName:<root> fileName:/genericFunWithStar.kt
CLASS INTERFACE name:IBase modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IBase
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:IFoo modality:ABSTRACT visibility:public superTypes:[<root>.IBase]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IFoo
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:IBar modality:ABSTRACT visibility:public superTypes:[<root>.IBase]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IBar
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:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.I<G of <root>.I>
TYPE_PARAMETER name:G index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
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:Box modality:ABSTRACT visibility:public superTypes:[<root>.IFoo; <root>.IBar]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Box<T of <root>.Box>
TYPE_PARAMETER name:T index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
CONSTRUCTOR visibility:public <> () returnType:<root>.Box<T of <root>.Box> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Box modality:ABSTRACT visibility:public superTypes:[<root>.IFoo; <root>.IBar]'
FUN name:foo visibility:public modality:ABSTRACT <F> ($this:<root>.Box<T of <root>.Box>, tSerializer:<root>.I<F of <root>.Box.foo>) returnType:<root>.I<<root>.Box<F of <root>.Box.foo>>
TYPE_PARAMETER name:F index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
$this: VALUE_PARAMETER name:<this> type:<root>.Box<T of <root>.Box>
VALUE_PARAMETER name:tSerializer index:0 type:<root>.I<F of <root>.Box.foo>
FUN name:bar visibility:public modality:FINAL <> ($this:<root>.Box<T of <root>.Box>, serializers:kotlin.Array<out <root>.I<*>>) returnType:<root>.I<*>
$this: VALUE_PARAMETER name:<this> type:<root>.Box<T of <root>.Box>
VALUE_PARAMETER name:serializers index:0 type:kotlin.Array<out <root>.I<*>> varargElementType:<root>.I<*> [vararg]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun bar (vararg serializers: <root>.I<*>): <root>.I<*> declared in <root>.Box'
CALL 'public abstract fun foo <F> (tSerializer: <root>.I<F of <root>.Box.foo>): <root>.I<<root>.Box<F of <root>.Box.foo>> declared in <root>.Box' type=<root>.I<out <root>.Box<out <root>.IFoo>> origin=null
<F>: <root>.IFoo
$this: GET_VAR '<this>: <root>.Box<T of <root>.Box> declared in <root>.Box.bar' type=<root>.Box<T of <root>.Box> origin=null
tSerializer: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.I<*> origin=null
$this: GET_VAR 'serializers: kotlin.Array<out <root>.I<*>> [vararg] declared in <root>.Box.bar' type=kotlin.Array<out <root>.I<*>> origin=null
index: CONST Int type=kotlin.Int value=0
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
+15
View File
@@ -0,0 +1,15 @@
interface IBase
interface IFoo : IBase
interface IBar : IBase
interface I<G> where G : IFoo, G : IBar {}
abstract class Box<T> : IFoo, IBar where T : IFoo, T : IBar {
abstract fun <F> foo(tSerializer: I<F>): I<Box<F>> where F : IFoo, F : IBar
fun bar(vararg serializers: I<*>): I<*> {
return foo(serializers[0])
}
}
+100
View File
@@ -0,0 +1,100 @@
FILE fqName:<root> fileName:/genericFunWithStar.kt
CLASS INTERFACE name:IBase modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IBase
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:IFoo modality:ABSTRACT visibility:public superTypes:[<root>.IBase]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IFoo
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>.IBase
$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>.IBase
$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>.IBase
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS INTERFACE name:IBar modality:ABSTRACT visibility:public superTypes:[<root>.IBase]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.IBar
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>.IBase
$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>.IBase
$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>.IBase
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.I<G of <root>.I>
TYPE_PARAMETER name:G index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
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:Box modality:ABSTRACT visibility:public superTypes:[<root>.IFoo; <root>.IBar]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Box<T of <root>.Box>
TYPE_PARAMETER name:T index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
CONSTRUCTOR visibility:public <> () returnType:<root>.Box<T of <root>.Box> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Box modality:ABSTRACT visibility:public superTypes:[<root>.IFoo; <root>.IBar]'
FUN name:foo visibility:public modality:ABSTRACT <F> ($this:<root>.Box<T of <root>.Box>, tSerializer:<root>.I<F of <root>.Box.foo>) returnType:<root>.I<<root>.Box<F of <root>.Box.foo>>
TYPE_PARAMETER name:F index:0 variance: superTypes:[<root>.IFoo; <root>.IBar]
$this: VALUE_PARAMETER name:<this> type:<root>.Box<T of <root>.Box>
VALUE_PARAMETER name:tSerializer index:0 type:<root>.I<F of <root>.Box.foo>
FUN name:bar visibility:public modality:FINAL <> ($this:<root>.Box<T of <root>.Box>, serializers:kotlin.Array<out <root>.I<*>>) returnType:<root>.I<*>
$this: VALUE_PARAMETER name:<this> type:<root>.Box<T of <root>.Box>
VALUE_PARAMETER name:serializers index:0 type:kotlin.Array<out <root>.I<*>> varargElementType:<root>.I<*> [vararg]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun bar (vararg serializers: <root>.I<*>): <root>.I<*> declared in <root>.Box'
CALL 'public abstract fun foo <F> (tSerializer: <root>.I<F of <root>.Box.foo>): <root>.I<<root>.Box<F of <root>.Box.foo>> declared in <root>.Box' type=<root>.I<out <root>.Box<*>> origin=null
<F>: <root>.IBase
$this: GET_VAR '<this>: <root>.Box<T of <root>.Box> declared in <root>.Box.bar' type=<root>.Box<T of <root>.Box> origin=null
tSerializer: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.I<*> origin=GET_ARRAY_ELEMENT
$this: GET_VAR 'serializers: kotlin.Array<out <root>.I<*>> [vararg] declared in <root>.Box.bar' type=kotlin.Array<out <root>.I<*>> origin=null
index: CONST Int type=kotlin.Int value=0
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>.IFoo
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.IBar
$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>.IFoo
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.IBar
$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>.IFoo
public open fun toString (): kotlin.String [fake_override] declared in <root>.IBar
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -1871,6 +1871,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/types/coercionToUnitInLambdaReturnValue.kt");
}
@TestMetadata("genericFunWithStar.kt")
public void testGenericFunWithStar() throws Exception {
runTest("compiler/testData/ir/irText/types/genericFunWithStar.kt");
}
@TestMetadata("genericPropertyReferenceType.kt")
public void testGenericPropertyReferenceType() throws Exception {
runTest("compiler/testData/ir/irText/types/genericPropertyReferenceType.kt");