[Test] Add test for KT-57456

This commit is contained in:
Dmitriy Novozhilov
2023-03-22 16:04:38 +02:00
committed by Space Team
parent 95d33da10d
commit a9c1091140
9 changed files with 636 additions and 0 deletions
@@ -5715,6 +5715,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
@TestDataPath("$PROJECT_ROOT")
public class ControlFlowAnalysis {
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_function.kt")
public void testAccessToCompanionInBaseEnumInitSection_function() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_function.kt");
}
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_property.kt")
public void testAccessToCompanionInBaseEnumInitSection_property() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.kt");
}
@Test
@TestMetadata("accessValueParameterInDefaultValue_after.kt")
public void testAccessValueParameterInDefaultValue_after() throws Exception {
@@ -5715,6 +5715,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
@TestDataPath("$PROJECT_ROOT")
public class ControlFlowAnalysis {
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_function.kt")
public void testAccessToCompanionInBaseEnumInitSection_function() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_function.kt");
}
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_property.kt")
public void testAccessToCompanionInBaseEnumInitSection_property() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.kt");
}
@Test
@TestMetadata("accessValueParameterInDefaultValue_after.kt")
public void testAccessValueParameterInDefaultValue_after() throws Exception {
@@ -5715,6 +5715,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
@TestDataPath("$PROJECT_ROOT")
public class ControlFlowAnalysis {
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_function.kt")
public void testAccessToCompanionInBaseEnumInitSection_function() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_function.kt");
}
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_property.kt")
public void testAccessToCompanionInBaseEnumInitSection_property() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.kt");
}
@Test
@TestMetadata("accessValueParameterInDefaultValue_after.kt")
public void testAccessValueParameterInDefaultValue_after() throws Exception {
@@ -5721,6 +5721,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
@TestDataPath("$PROJECT_ROOT")
public class ControlFlowAnalysis {
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_function.kt")
public void testAccessToCompanionInBaseEnumInitSection_function() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_function.kt");
}
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_property.kt")
public void testAccessToCompanionInBaseEnumInitSection_property() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.kt");
}
@Test
@TestMetadata("accessValueParameterInDefaultValue_after.kt")
public void testAccessValueParameterInDefaultValue_after() throws Exception {
@@ -0,0 +1,144 @@
// DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_STDLIB
// ISSUE: KT-57456, KT-57608
@file:OptIn(ExperimentalContracts::class)
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
enum class Enum {
A {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
},
B {
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
},
C {
init {
class Local {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
fun localFun() {
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
}
}
}
},
D {
init {
val someObj = object {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
fun localFun() {
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
}
}
}
}
;
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
companion object {
fun foo(): String = "foo()"
}
}
enum class EnumWithConstructor(val a: String, val b: String, val c: String) {
A(
a = <!UNINITIALIZED_ENUM_COMPANION!>foo<!>(),
b = inPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>foo<!>() },
c = nonInPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>foo<!>() }
);
companion object {
fun foo(): String = "foo()"
}
}
operator fun <T> T.provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty<Any?, T> = ReadOnlyProperty { _, _ -> this }
inline fun <T> inPlaceRun(block: () -> T): T {
contract { callsInPlace(block) }
return block()
}
fun <T> nonInPlaceRun(block: () -> T): T {
return block()
}
inline fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
contract { callsInPlace(block) }
val value = block()
return ReadOnlyProperty { _, _ -> value }
}
fun <T> nonInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, _ -> block() }
}
@@ -0,0 +1,144 @@
// DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_STDLIB
// ISSUE: KT-57456, KT-57608
@file:OptIn(ExperimentalContracts::class)
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
enum class Enum {
A {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
},
B {
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
},
C {
init {
class Local {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
fun localFun() {
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
}
}
}
},
D {
init {
val someObj = object {
val aInside = foo()
val bInside = inPlaceRun { foo() }
val cInside = nonInPlaceRun { foo() }
val dInside by foo()
val eInside by inPlaceDelegate { foo() }
val fInside by nonInPlaceDelegate { foo() }
init {
val aInit = foo()
val bInit = inPlaceRun { foo() }
val cInit = nonInPlaceRun { foo() }
val dInit by foo()
val eInit by inPlaceDelegate { foo() }
val fInit by nonInPlaceDelegate { foo() }
}
fun localFun() {
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
}
}
}
}
;
val a = foo()
val b = inPlaceRun { foo() }
val c = nonInPlaceRun { foo() }
val d by foo()
val e by inPlaceDelegate { foo() }
val f by nonInPlaceDelegate { foo() }
companion object {
fun foo(): String = "foo()"
}
}
enum class EnumWithConstructor(val a: String, val b: String, val c: String) {
A(
a = <!UNINITIALIZED_ENUM_COMPANION!>foo()<!>,
b = inPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>foo()<!> },
c = nonInPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>foo()<!> }
);
companion object {
fun foo(): String = "foo()"
}
}
operator fun <T> T.provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty<Any?, T> = ReadOnlyProperty { _, _ -> this }
inline fun <T> inPlaceRun(block: () -> T): T {
contract { callsInPlace(block) }
return block()
}
fun <T> nonInPlaceRun(block: () -> T): T {
return block()
}
inline fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
contract { callsInPlace(block) }
val value = block()
return ReadOnlyProperty { _, _ -> value }
}
fun <T> nonInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, _ -> block() }
}
@@ -0,0 +1,144 @@
// DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_STDLIB
// ISSUE: KT-57456, KT-57608
@file:OptIn(ExperimentalContracts::class)
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
enum class Enum {
A {
val aInside = value
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by value
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
},
B {
init {
val aInit = value
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by value
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
},
C {
init {
class Local {
val aInside = value
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by value
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = value
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by value
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
},
D {
init {
val someObj = object {
val aInside = value
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by value
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = value
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by value
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
}
;
val a = <!UNINITIALIZED_VARIABLE!>value<!>
val b = inPlaceRun { <!UNINITIALIZED_VARIABLE!>value<!> }
val c = nonInPlaceRun { <!UNINITIALIZED_VARIABLE!>value<!> }
val d by <!UNINITIALIZED_VARIABLE!>value<!>
val e by inPlaceDelegate { <!UNINITIALIZED_VARIABLE!>value<!> }
val f by nonInPlaceDelegate { <!UNINITIALIZED_VARIABLE!>value<!> }
companion object {
val value = "value"
}
}
enum class EnumWithConstructor(val a: String, val b: String, val c: String) {
A(
a = <!UNINITIALIZED_ENUM_COMPANION, UNINITIALIZED_VARIABLE!>value<!>,
b = inPlaceRun { <!UNINITIALIZED_ENUM_COMPANION, UNINITIALIZED_VARIABLE!>value<!> },
c = nonInPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>value<!> }
);
companion object {
val value = "value"
}
}
operator fun <T> T.provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty<Any?, T> = ReadOnlyProperty { _, _ -> this }
inline fun <T> inPlaceRun(block: () -> T): T {
contract { callsInPlace(block) }
return block()
}
fun <T> nonInPlaceRun(block: () -> T): T {
return block()
}
inline fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
contract { callsInPlace(block) }
val value = block()
return ReadOnlyProperty { _, _ -> value }
}
fun <T> nonInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, _ -> block() }
}
@@ -0,0 +1,144 @@
// DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_STDLIB
// ISSUE: KT-57456, KT-57608
@file:OptIn(ExperimentalContracts::class)
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
enum class Enum {
A {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
},
B {
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
},
C {
init {
class Local {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
},
D {
init {
val someObj = object {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
}
;
val a = <!UNINITIALIZED_VARIABLE!>value<!>
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by <!UNINITIALIZED_VARIABLE!>value<!>
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
companion object {
val value = "value"
}
}
enum class EnumWithConstructor(val a: String, val b: String, val c: String) {
A(
a = <!UNINITIALIZED_ENUM_COMPANION, UNINITIALIZED_VARIABLE!>value<!>,
b = inPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>value<!> },
c = nonInPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>value<!> }
);
companion object {
val value = "value"
}
}
operator fun <T> T.provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty<Any?, T> = ReadOnlyProperty { _, _ -> this }
inline fun <T> inPlaceRun(block: () -> T): T {
contract { callsInPlace(block) }
return block()
}
fun <T> nonInPlaceRun(block: () -> T): T {
return block()
}
inline fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
contract { callsInPlace(block) }
val value = block()
return ReadOnlyProperty { _, _ -> value }
}
fun <T> nonInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, _ -> block() }
}
@@ -5721,6 +5721,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
@TestDataPath("$PROJECT_ROOT")
public class ControlFlowAnalysis {
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_function.kt")
public void testAccessToCompanionInBaseEnumInitSection_function() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_function.kt");
}
@Test
@TestMetadata("accessToCompanionInBaseEnumInitSection_property.kt")
public void testAccessToCompanionInBaseEnumInitSection_property() throws Exception {
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.kt");
}
@Test
@TestMetadata("accessValueParameterInDefaultValue_after.kt")
public void testAccessValueParameterInDefaultValue_after() throws Exception {