From 8664fc3b28df4e239c9e342a38e780c40ab18055 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 22 Mar 2019 13:48:29 +0300 Subject: [PATCH] psi2ir: add test for implicit cast on values of intersection type --- .../types/localVariableOfIntersectionType.kt | 27 ++++ .../types/localVariableOfIntersectionType.txt | 126 ++++++++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 5 + 3 files changed, 158 insertions(+) create mode 100644 compiler/testData/ir/irText/types/localVariableOfIntersectionType.kt create mode 100644 compiler/testData/ir/irText/types/localVariableOfIntersectionType.txt diff --git a/compiler/testData/ir/irText/types/localVariableOfIntersectionType.kt b/compiler/testData/ir/irText/types/localVariableOfIntersectionType.kt new file mode 100644 index 00000000000..b3cd92daeca --- /dev/null +++ b/compiler/testData/ir/irText/types/localVariableOfIntersectionType.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +NewInference + +interface In + +interface Inv { + val t: T +} + +interface Z { + fun create(x: In, y: In): Inv +} + +interface IA { + fun foo() +} + +interface IB { + fun bar() +} + +fun test(a: In, b: In, z: Z) { + z.create(a, b).t.foo() + z.create(a, b).t.bar() + val t = z.create(a, b).t + t.foo() + t.bar() +} diff --git a/compiler/testData/ir/irText/types/localVariableOfIntersectionType.txt b/compiler/testData/ir/irText/types/localVariableOfIntersectionType.txt new file mode 100644 index 00000000000..728302d8111 --- /dev/null +++ b/compiler/testData/ir/irText/types/localVariableOfIntersectionType.txt @@ -0,0 +1,126 @@ +FILE fqName: fileName:/localVariableOfIntersectionType.kt + CLASS INTERFACE name:In modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.In.In> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: 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 + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:Inv modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Inv.Inv> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + PROPERTY name:t visibility:public modality:ABSTRACT [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.Inv.Inv>) returnType:T of .Inv + correspondingProperty: PROPERTY name:t visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.Inv.Inv> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: 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 + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:Z modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z + FUN name:create visibility:public modality:ABSTRACT ($this:.Z, x:.In.Z.create>, y:.In.Z.create>) returnType:.Inv.Z.create> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.Z + VALUE_PARAMETER name:x index:0 type:.In.Z.create> + VALUE_PARAMETER name:y index:1 type:.In.Z.create> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: 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 + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IA modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IA + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IA) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IA + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: 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 + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IB modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IB + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.IB) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IB + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: 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 + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test visibility:public modality:FINAL <> (a:.In<.IA>, b:.In<.IB>, z:.Z) returnType:kotlin.Unit + VALUE_PARAMETER name:a index:0 type:.In<.IA> + VALUE_PARAMETER name:b index:1 type:.In<.IB> + VALUE_PARAMETER name:z index:2 type:.Z + BLOCK_BODY + CALL 'public abstract fun foo (): kotlin.Unit declared in .IA' type=kotlin.Unit origin=null + $this: TYPE_OP type=.IA origin=IMPLICIT_CAST typeOperand=.IA + CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + : kotlin.Any + $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null + x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null + y: GET_VAR 'b: .In<.IB> declared in .test' type=.In<.IB> origin=null + CALL 'public abstract fun bar (): kotlin.Unit declared in .IB' type=kotlin.Unit origin=null + $this: TYPE_OP type=.IB origin=IMPLICIT_CAST typeOperand=.IB + CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + : kotlin.Any + $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null + x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null + y: GET_VAR 'b: .In<.IB> declared in .test' type=.In<.IB> origin=null + VAR name:t type:kotlin.Any [val] + TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any + CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + : kotlin.Any + $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null + x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null + y: GET_VAR 'b: .In<.IB> declared in .test' type=.In<.IB> origin=null + CALL 'public abstract fun foo (): kotlin.Unit declared in .IA' type=kotlin.Unit origin=null + $this: TYPE_OP type=.IA origin=IMPLICIT_CAST typeOperand=.IA + GET_VAR 'val t: kotlin.Any [val] declared in .test' type=kotlin.Any origin=null + CALL 'public abstract fun bar (): kotlin.Unit declared in .IB' type=kotlin.Unit origin=null + $this: TYPE_OP type=.IB origin=IMPLICIT_CAST typeOperand=.IB + GET_VAR 'val t: kotlin.Any [val] declared in .test' type=kotlin.Any origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index b2cf40867e0..a3a75312de9 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1590,5 +1590,10 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { public void testIntersectionType3() throws Exception { runTest("compiler/testData/ir/irText/types/intersectionType3.kt"); } + + @TestMetadata("localVariableOfIntersectionType.kt") + public void testLocalVariableOfIntersectionType() throws Exception { + runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType.kt"); + } } }