Special enum function support; Fix for KT-10569: Cannot iterate over values of an enum class when it is used as a generic parameter

#KT-10569 Fixed
This commit is contained in:
Michael Bogdanov
2016-11-02 12:32:47 +03:00
parent 6a3597fa0f
commit fd6d4c352c
28 changed files with 547 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
var result = ""
inline fun <reified T : Enum<T>> renderOptions(render: (T) -> String) {
val values = enumValues<T>()
for (v in values) {
result += render(v)
}
}
enum class Z {
O, K;
val myParam = name
}
// FILE: 2.kt
import test.*
fun box(): String {
renderOptions<Z> {
it.myParam
}
return result
}
+20
View File
@@ -0,0 +1,20 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return enumValueOf<T>("OK").name
}
enum class Z {
OK
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValueOf<Z>()
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return { enumValueOf<T>("OK") }().name
}
enum class Z {
OK
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValueOf<Z>()
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return myValueOf2<T>()
}
inline fun <reified Y : Enum<Y>> myValueOf2(): String {
return enumValueOf<Y>("OK").name
}
enum class Z {
OK
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValueOf<Z>()
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return myValueOf2<T>()
}
inline fun <reified Y : Enum<Y>> myValueOf2(): String {
return { enumValueOf<Y>("OK").name }()
}
enum class Z {
OK
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValueOf<Z>()
}
@@ -0,0 +1,20 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun myValueOf(): String {
return enumValueOf<Z>("OK").name
}
enum class Z {
OK
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValueOf()
}
+21
View File
@@ -0,0 +1,21 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValues(): String {
val values = enumValues<T>()
return values.joinToString("")
}
enum class Z {
O, K
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValues<Z>()
}
@@ -0,0 +1,26 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValues(): Array<T> {
return enumValues<T>()
}
enum class Z {
O, K;
val myParam = name
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(myValues<Z>())
}
fun test(myValues: Array<Z>): String {
return myValues.map { it.myParam }.joinToString ("");
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValues(): String {
val values = { enumValues<T>() }()
return values.joinToString("")
}
enum class Z {
O, K
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValues<Z>()
}
+25
View File
@@ -0,0 +1,25 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified Y : Enum<Y>> myValues2(): String {
val values = enumValues<Y>()
return values.joinToString("")
}
inline fun <reified T : Enum<T>> myValues(): String {
return myValues2<T>()
}
enum class Z {
O, K
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValues<Z>()
}
@@ -0,0 +1,25 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified Y : Enum<Y>> myValues2(): String {
val values = { enumValues<Y>() }()
return values.joinToString("")
}
inline fun <reified T : Enum<T>> myValues(): String {
return myValues2<T>()
}
enum class Z {
O, K
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValues<Z>()
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun myValues(): String {
val values = enumValues<Z>()
return values.joinToString("")
}
enum class Z {
O, K
}
// FILE: 2.kt
import test.*
fun box(): String {
return myValues()
}