Make CharSequence.length a function instead of property
And String.length as well. This is done for JVM interoperability: java.lang.CharSequence is an open class and has a function 'length()' which should be implemented in subclasses somehow. A minor unexpected effect of this is that String.length() is now a compile-time constant (it wasn't such as a property because properties are not supported in compile-time constant evaluation) #KT-3571 Fixed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import java.util.*
|
||||
|
||||
import java.io.*
|
||||
@@ -10,7 +9,7 @@ fun takeFirst(expr: StringBuilder): Char {
|
||||
}
|
||||
|
||||
fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
|
||||
if (expr.length == 0) throw Exception("Syntax error: Character expected");
|
||||
if (expr.length() == 0) throw Exception("Syntax error: Character expected");
|
||||
val c = takeFirst(<!TYPE_MISMATCH!>expr<!>)
|
||||
if (c >= '0' && c <= '9') {
|
||||
val n = c - '0'
|
||||
|
||||
@@ -3,7 +3,7 @@ package jet121
|
||||
fun box() : String {
|
||||
val answer = apply("OK") { String.() : Int ->
|
||||
get(0)
|
||||
length
|
||||
length()
|
||||
}
|
||||
|
||||
return if (answer == 2) "OK" else "FAIL"
|
||||
|
||||
@@ -11,7 +11,7 @@ package demo
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
for (a in filter(args, {it.length > 1})) {
|
||||
for (a in filter(args, {it.length() > 1})) {
|
||||
System.out.println("Hello, ${a}!")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ fun main() {
|
||||
val diffs = ArrayList<Int>()
|
||||
for (i in vals.indices) {
|
||||
for (j in i..vals.lastIndex()) // Type inference failed
|
||||
diffs.add(vals[i].length - vals[j].length)
|
||||
diffs.add(vals[i].length() - vals[j].length())
|
||||
for (j in i..vals.lastIndex) // Type inference failed
|
||||
diffs.add(vals[i].length - vals[j].length)
|
||||
diffs.add(vals[i].length() - vals[j].length())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user