Files
kotlin-fork/kotlin-native/backend.native/tests/codegen/basics/k42000_1.kt
T
Stanislav Erokhin f624800b84 Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
2020-10-27 21:00:28 +03:00

38 lines
914 B
Kotlin

package codegen.basics.k42000_1
import kotlin.test.*
@Test
fun runTest() {
assertTrue(Reproducer().repro() > 0)
}
// Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0
val Int.isEven get() = this % 2 == 0
inline operator fun <reified T : Number> T.plus(other: T): T = when (T::class) {
Double::class -> (this as Double) + (other as Double)
Int::class -> (this as Int) + (other as Int)
Long::class -> (this as Long) + (other as Long)
else -> TODO()
} as T
inline fun <reified T : Number> Collection<T>.median(): Double {
val sorted = this.sortedBy {
it.toDouble()
}
return if (size.isEven || size == 1) {
sorted[size / 2]
} else {
sorted[size / 2] + sorted[size / 2 + 1]
}.toDouble()
}
class Reproducer {
private var someListOfLongs = mutableListOf<Long>(1L)
fun repro() = someListOfLongs.median()
}