K2: reproduce strange "smartcast aside" behavior related to KT-62544 fix

This commit is contained in:
Mikhail Glukhikh
2023-10-27 14:42:08 +02:00
committed by Space Team
parent 9c146adc3a
commit 1ef0f9e944
16 changed files with 337 additions and 0 deletions
@@ -2008,6 +2008,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -2008,6 +2008,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest {
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -0,0 +1,80 @@
FILE fqName:<root> fileName:/smartCastAside.kt
CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
FUN name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit
$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 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:B modality:ABSTRACT visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
FUN name:bar visibility:public modality:ABSTRACT <> ($this:<root>.B) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.B
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit [fake_override]
overridden:
public abstract fun foo (): kotlin.Unit 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 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 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 declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS INTERFACE name:C modality:ABSTRACT visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
FUN name:baz visibility:public modality:ABSTRACT <> ($this:<root>.C) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.C
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit [fake_override]
overridden:
public abstract fun foo (): kotlin.Unit 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 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 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 declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:test visibility:public modality:FINAL <> (param:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:param index:0 type:<root>.B
BLOCK_BODY
WHEN type=kotlin.Unit origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.C
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.A' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.C origin=IMPLICIT_CAST typeOperand=<root>.C
TYPE_OP type=<root>.A origin=IMPLICIT_CAST typeOperand=<root>.A
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
CALL 'public abstract fun bar (): kotlin.Unit declared in <root>.B' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
TYPE_OP type=<root>.A origin=IMPLICIT_CAST typeOperand=<root>.A
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
CALL 'public abstract fun baz (): kotlin.Unit declared in <root>.C' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.C origin=IMPLICIT_CAST typeOperand=<root>.C
TYPE_OP type=<root>.A origin=IMPLICIT_CAST typeOperand=<root>.A
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
@@ -0,0 +1,24 @@
interface A {
abstract fun foo()
}
interface B : A {
abstract fun bar()
}
interface C : A {
abstract fun baz()
}
fun test(param: B) {
when {
param is C -> { // BLOCK
param /*as A */ /*as C */.foo()
param /*as A */ /*as B */.bar()
param /*as A */ /*as C */.baz()
}
}
}
@@ -0,0 +1,75 @@
FILE fqName:<root> fileName:/smartCastAside.kt
CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
FUN name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit
$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 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:B modality:ABSTRACT visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
FUN name:bar visibility:public modality:ABSTRACT <> ($this:<root>.B) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.B
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit [fake_override]
overridden:
public abstract fun foo (): kotlin.Unit 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 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 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 declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS INTERFACE name:C modality:ABSTRACT visibility:public superTypes:[<root>.A]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
FUN name:baz visibility:public modality:ABSTRACT <> ($this:<root>.C) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.C
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Unit [fake_override]
overridden:
public abstract fun foo (): kotlin.Unit 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 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 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 declared in <root>.A
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:test visibility:public modality:FINAL <> (param:<root>.B) returnType:kotlin.Unit
VALUE_PARAMETER name:param index:0 type:<root>.B
BLOCK_BODY
WHEN type=kotlin.Unit origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.C
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
then: BLOCK type=kotlin.Unit origin=null
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.B' type=kotlin.Unit origin=null
$this: GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
CALL 'public abstract fun bar (): kotlin.Unit declared in <root>.B' type=kotlin.Unit origin=null
$this: GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
CALL 'public abstract fun baz (): kotlin.Unit declared in <root>.C' type=kotlin.Unit origin=null
$this: TYPE_OP type=<root>.C origin=IMPLICIT_CAST typeOperand=<root>.C
GET_VAR 'param: <root>.B declared in <root>.test' type=<root>.B origin=null
@@ -0,0 +1,19 @@
interface A {
fun foo()
}
interface B : A {
fun bar()
}
interface C : A {
fun baz()
}
fun test(param: B) {
if (param is C) {
param.foo()
param.bar()
param.baz()
}
}
@@ -0,0 +1,24 @@
interface A {
abstract fun foo()
}
interface B : A {
abstract fun bar()
}
interface C : A {
abstract fun baz()
}
fun test(param: B) {
when {
param is C -> { // BLOCK
param.foo()
param.bar()
param /*as C */.baz()
}
}
}
@@ -0,0 +1,56 @@
// CHECK:
// Mangled name: A
// Public signature: /A|null[0]
interface A {
// CHECK:
// Mangled name: A#foo(){}
// Public signature: /A.foo|-1041209573719867811[0]
// Public signature debug description: foo(){}
abstract fun foo(): Unit
}
// CHECK:
// Mangled name: B
// Public signature: /B|null[0]
interface B : A {
// CHECK:
// Mangled name: B#foo(){}
// Public signature: /B.foo|-1041209573719867811[0]
// Public signature debug description: foo(){}
abstract /* fake */ override fun foo(): Unit
// CHECK:
// Mangled name: B#bar(){}
// Public signature: /B.bar|496682602797471549[0]
// Public signature debug description: bar(){}
abstract fun bar(): Unit
}
// CHECK:
// Mangled name: C
// Public signature: /C|null[0]
interface C : A {
// CHECK:
// Mangled name: C#foo(){}
// Public signature: /C.foo|-1041209573719867811[0]
// Public signature debug description: foo(){}
abstract /* fake */ override fun foo(): Unit
// CHECK:
// Mangled name: C#baz(){}
// Public signature: /C.baz|-7957790288607863798[0]
// Public signature debug description: baz(){}
abstract fun baz(): Unit
}
// CHECK:
// Mangled name: #test(B){}
// Public signature: /test|3809392349795657853[0]
// Public signature debug description: test(B){}
fun test(param: B): Unit
@@ -2008,6 +2008,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1533,6 +1533,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase {
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCasts.kt");
@@ -1756,6 +1756,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1756,6 +1756,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest {
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1756,6 +1756,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest {
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1756,6 +1756,12 @@ public class ClassicNativeIrTextTestGenerated extends AbstractClassicNativeIrTex
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1756,6 +1756,12 @@ public class FirLightTreeNativeIrTextTestGenerated extends AbstractFirLightTreeN
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
@@ -1756,6 +1756,12 @@ public class FirPsiNativeIrTextTestGenerated extends AbstractFirPsiNativeIrTextT
runTest("compiler/testData/ir/irText/expressions/simpleUnaryOperators.kt");
}
@Test
@TestMetadata("smartCastAside.kt")
public void testSmartCastAside() throws Exception {
runTest("compiler/testData/ir/irText/expressions/smartCastAside.kt");
}
@Test
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {