Reproduction of issue KT-18254.
Last active
November 4, 2017 16:37
-
-
Save edudobay/a92c4f97396aa90ecd2916c23da69cfc to your computer and use it in GitHub Desktop.
Kotlin reified types issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
ext.kotlin_version = '1.2.0-rc-39' | |
repositories { | |
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } | |
jcenter() | |
} | |
dependencies { | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |
} | |
} | |
apply plugin: 'kotlin' | |
apply plugin: 'application' | |
sourceSets { | |
main.kotlin.srcDirs += '.' | |
} | |
repositories { | |
jcenter() | |
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } | |
} | |
dependencies { | |
compile "org.jetbrains.kotlin:kotlin-stdlib" | |
} | |
mainClassName = 'EnumValueKt' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Gender { | |
MALE, FEMALE | |
} | |
inline fun <reified T : Enum<T>> wrapEnumValueOf(name: String) = enumValueOf<T>(name) | |
inline fun postInline(block: () -> Unit) = block() | |
fun post(block: () -> Unit) = block() | |
typealias Action = () -> Unit | |
object RunCases { | |
val cases = mapOf<String, Action>( | |
"unwrapped inline" to ::unwrapped_inline, | |
"unwrapped noinline" to ::unwrapped_noinline, | |
"wrapped inline" to ::wrapped_inline, | |
"wrapped noinline" to ::wrapped_noinline | |
) | |
fun unwrapped_inline() { | |
postInline { println(enumValueOf<Gender>("MALE")) } | |
} | |
fun unwrapped_noinline() { | |
post { println(enumValueOf<Gender>("MALE")) } | |
} | |
fun wrapped_inline() { | |
postInline { println(wrapEnumValueOf<Gender>("MALE")) } | |
} | |
fun wrapped_noinline() { | |
post { println(wrapEnumValueOf<Gender>("MALE")) } | |
} | |
} | |
fun main(args: Array<String>) { | |
RunCases.cases.forEach { (name, block) -> | |
println(">>> Running: $name") | |
try { | |
block() | |
} catch (error: Throwable) { | |
error.printStackTrace(System.out) | |
} | |
println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment