JVM IR: lookup symbols by name in ProgressionHandlers in known classes only
Alternatively, we could improve the lookup utilities and their usages to always find the exact override of a symbol from Collection/Iterable/CharSequence/etc, but since we need to load the original symbol anyway in cases when the loop subject's type is a type parameter, we might as well simplify everything and always reference the original symbol. Also improve exception message and removed unused declarations in IrBackendUtils.kt.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
class C : CharSequence {
|
||||
// Unused declarations, which are here only to confuse the backend who might lookup symbols by name
|
||||
private val List<String>.length: Int
|
||||
get() = size
|
||||
private operator fun List<String>.get(i: Int) =
|
||||
this.get(i)
|
||||
|
||||
override val length: Int
|
||||
get() = 2
|
||||
|
||||
override fun get(index: Int): Char =
|
||||
if (index == 0) 'O' else 'K'
|
||||
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence =
|
||||
throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
val c = C()
|
||||
for (i in c.indices) {
|
||||
if (i == 0) {
|
||||
result += c[i]
|
||||
}
|
||||
}
|
||||
for ((i, x) in c.withIndex()) {
|
||||
if (i == 1) {
|
||||
result += x
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
class C : Iterable<String> {
|
||||
// Unused declaration, which is here only to confuse the backend who might lookup symbols by name
|
||||
private fun List<Int>.iterator(): Double = size.toDouble()
|
||||
|
||||
override fun iterator(): Iterator<String> = listOf("OK").iterator()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
for ((i, x) in c.withIndex()) {
|
||||
if (i == 0) {
|
||||
return x
|
||||
}
|
||||
}
|
||||
return "Fail"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val a = ArrayList<String>()
|
||||
a.add("OK")
|
||||
for (i in a.indices) {
|
||||
return a[i]
|
||||
}
|
||||
return "Fail"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val a = ArrayList<String>()
|
||||
a.add("OK")
|
||||
for (i in a.indices) {
|
||||
return a[i]
|
||||
}
|
||||
return "Fail"
|
||||
}
|
||||
|
||||
// 0 iterator
|
||||
Reference in New Issue
Block a user