[IR] Fix issue getting the length property from CharSequence bounded type parameter
Use the class of the subtype of CharSequence when available. When it is not (for type parameters bounded by CharSequence) call the CharSequence getter and 'get' method. Using the most specific type posible fixes the forInStringSpecialized test that expects the use of INVOKEVIRTUAL and not INVOKEINTERFACE. Add tests for the type parameter use.
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
fun <T: CharSequence> test(sequence: T) {
|
||||
var s = ""
|
||||
for (c in sequence) {
|
||||
s += c
|
||||
}
|
||||
}
|
||||
|
||||
// 0 iterator
|
||||
// 0 hasNext
|
||||
// 0 nextChar
|
||||
compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCharSequenceTypeParameterIndices.kt
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
fun <T: CharSequence> test(s: T): Int {
|
||||
var result = 0
|
||||
for (i in s.indices) {
|
||||
result = result * 10 + (i + 1)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// JVM non-IR uses while.
|
||||
// JVM IR uses if + do-while.
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
// 0 getEnd
|
||||
// 0 getFirst
|
||||
// 0 getLast
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 0 IF_ICMPGT
|
||||
// 0 IF_ICMPEQ
|
||||
// 1 IF_ICMPGE
|
||||
// 1 IF
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPLE
|
||||
// 2 IF
|
||||
Reference in New Issue
Block a user