Fix KT-42000

This commit is contained in:
SvyatoslavScherbina
2020-09-24 11:45:31 +03:00
committed by GitHub
parent e85e87620c
commit f76cf52c81
4 changed files with 61 additions and 1 deletions
@@ -1337,7 +1337,8 @@ internal class FunctionGenerationContext(val function: LLVMValueRef,
fun getBuilder(): LLVMBuilderRef {
if (isAfterTerminator) {
positionAtEnd(basicBlock("unreachable", null))
val position = position()
positionAtEnd(basicBlock("unreachable", position?.start, position?.end))
}
return builder
+8
View File
@@ -2917,6 +2917,14 @@ task unit4(type: KonanLocalTest) {
source = "codegen/basics/unit4.kt"
}
task kt42000_1(type: KonanLocalTest) {
source = "codegen/basics/k42000_1.kt"
}
task kt42000_2(type: KonanLocalTest) {
source = "codegen/basics/k42000_2.kt"
}
task inline0(type: KonanLocalTest) {
goldValue = "84\n"
source = "codegen/inline/inline0.kt"
@@ -0,0 +1,37 @@
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()
}
@@ -0,0 +1,14 @@
package codegen.basics.k42000_2
import kotlin.test.*
// https://youtrack.jetbrains.com/issue/KT-42000
@Test
fun runTest() {
assertFailsWith<Error> {
when (1) {
else -> throw Error()
} as String
}
}