[FE 1.0] Prohibit access to members of companion of enum from enum entry initializer

^KT-49461 Fixed
^KT-49110
This commit is contained in:
Dmitriy Novozhilov
2021-10-28 15:40:15 +03:00
committed by TeamCityServer
parent 4f0c3c3c0d
commit 58889a2b5c
14 changed files with 422 additions and 6 deletions
@@ -0,0 +1,39 @@
// LANGUAGE: -ProhibitAccessToEnumCompanionMembersInEnumConstructorCall
// ISSUE: KT-49110
enum class SomeEnum(val x: Int) {
A(<!UNINITIALIZED_ENUM_COMPANION!>companionFun<!>().length),// UNINITIALIZED_ENUM_COMPANION
B(<!UNINITIALIZED_ENUM_COMPANION_WARNING, UNINITIALIZED_VARIABLE!>companionProp<!>.length), // UNINITIALIZED_VARIABLE
C(<!UNINITIALIZED_ENUM_COMPANION_WARNING!>SomeEnum<!>.companionFun().length),
D(<!UNINITIALIZED_ENUM_COMPANION_WARNING!>SomeEnum<!>.companionProp.length),
E(SomeEnum.<!UNINITIALIZED_ENUM_COMPANION_WARNING!>Companion<!>.companionFun().length),
F(SomeEnum.<!UNINITIALIZED_ENUM_COMPANION_WARNING!>Companion<!>.<!UNINITIALIZED_VARIABLE!>companionProp<!>.length); // UNINITIALIZED_VARIABLE
companion object {
val companionProp = "someString"
fun companionFun(): String = "someString"
}
}
enum class OtherEnum(val x: Int) {
G(<!UNINITIALIZED_ENUM_COMPANION!>extensionFun<!>().length), // UNINITIALIZED_ENUM_COMPANION
H(<!UNINITIALIZED_ENUM_COMPANION_WARNING!>extensionProp<!>.length),
I(<!UNINITIALIZED_ENUM_COMPANION_WARNING!>OtherEnum<!>.extensionFun().length),
J(<!UNINITIALIZED_ENUM_COMPANION_WARNING!>OtherEnum<!>.extensionProp.length),
K(OtherEnum.<!UNINITIALIZED_ENUM_COMPANION_WARNING!>Companion<!>.extensionFun().length),
L(OtherEnum.<!UNINITIALIZED_ENUM_COMPANION_WARNING!>Companion<!>.extensionProp.length);
companion object {
val companionProp = "someString"
fun companionFun(): String = "someString"
}
}
fun OtherEnum.Companion.extensionFun(): String = companionFun()
val OtherEnum.Companion.extensionProp: String
get() = companionProp