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:
@@ -130,9 +130,6 @@ public class IntrinsicMethods {
|
||||
declareIntrinsicFunction(typeName + "Iterator", "next", 0, ITERATOR_NEXT);
|
||||
}
|
||||
|
||||
declareIntrinsicProperty("CharSequence", "length", new StringLength());
|
||||
declareIntrinsicProperty("String", "length", new StringLength());
|
||||
|
||||
declareArrayMethods();
|
||||
}
|
||||
|
||||
@@ -168,10 +165,6 @@ public class IntrinsicMethods {
|
||||
}
|
||||
}
|
||||
|
||||
private void declareIntrinsicProperty(@NotNull String className, @NotNull String methodName, @NotNull IntrinsicMethod implementation) {
|
||||
declareIntrinsicFunction(className, methodName, -1, implementation);
|
||||
}
|
||||
|
||||
private void declareIntrinsicFunction(
|
||||
@NotNull String className,
|
||||
@NotNull String methodName,
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.intrinsics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen
|
||||
import org.jetbrains.jet.codegen.StackValue
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
|
||||
public class StringLength : LazyIntrinsicMethod() {
|
||||
override fun generateImpl(
|
||||
codegen: ExpressionCodegen,
|
||||
returnType: Type,
|
||||
element: PsiElement?,
|
||||
arguments: List<JetExpression>,
|
||||
receiver: StackValue
|
||||
): StackValue {
|
||||
return StackValue.operation(Type.INT_TYPE) {
|
||||
receiver.put(receiver.type, it)
|
||||
it.invokeinterface("java/lang/CharSequence", "length", "()I")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
|
||||
unaryOperation(SHORT, "toLong", { a -> a.toLong() }, emptyUnaryFun),
|
||||
unaryOperation(SHORT, "toShort", { a -> a.toShort() }, emptyUnaryFun),
|
||||
unaryOperation(SHORT, "toString", { a -> a.toString() }, emptyUnaryFun),
|
||||
unaryOperation(STRING, "length", { a -> a.length() }, emptyUnaryFun),
|
||||
unaryOperation(STRING, "toString", { a -> a.toString() }, emptyUnaryFun)
|
||||
)
|
||||
|
||||
|
||||
@@ -294,9 +294,8 @@ public final class CharRange : kotlin.Range<kotlin.Char>, kotlin.Progression<kot
|
||||
}
|
||||
|
||||
public trait CharSequence {
|
||||
public abstract val length: kotlin.Int
|
||||
public abstract fun <get-length>(): kotlin.Int
|
||||
public abstract fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public abstract fun length(): kotlin.Int
|
||||
}
|
||||
|
||||
public trait Cloneable {
|
||||
@@ -1429,10 +1428,9 @@ public final class ShortRange : kotlin.Range<kotlin.Short>, kotlin.Progression<k
|
||||
|
||||
public final class String : kotlin.Comparable<kotlin.String>, kotlin.CharSequence {
|
||||
/*primary*/ public constructor String()
|
||||
public open override /*1*/ val length: kotlin.Int
|
||||
public open override /*1*/ fun <get-length>(): kotlin.Int
|
||||
public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
|
||||
public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public final fun plus(/*0*/ other: kotlin.Any?): kotlin.String
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
== test ==
|
||||
fun test(s: String?) {
|
||||
s?.length
|
||||
fun test(s: IntProgression?) {
|
||||
s?.start
|
||||
}
|
||||
---------------------
|
||||
L0:
|
||||
1 <START>
|
||||
v(s: String?)
|
||||
magic[FAKE_INITIALIZER](s: String?) -> <v0>
|
||||
v(s: IntProgression?)
|
||||
magic[FAKE_INITIALIZER](s: IntProgression?) -> <v0>
|
||||
w(s|<v0>)
|
||||
2 mark({ s?.length })
|
||||
mark(s?.length)
|
||||
2 mark({ s?.start })
|
||||
mark(s?.start)
|
||||
r(s) -> <v1>
|
||||
r(length|<v1>) -> <v2>
|
||||
r(start|<v1>) -> <v2>
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>]
|
||||
1 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
fun test(s: String?) {
|
||||
s?.length
|
||||
}
|
||||
fun test(s: IntProgression?) {
|
||||
s?.start
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
== test ==
|
||||
fun test(s: String?) {
|
||||
s?.length
|
||||
fun test(s: IntProgression?) {
|
||||
s?.start
|
||||
}
|
||||
---------------------
|
||||
<v0>: {<: String?} NEW: magic[FAKE_INITIALIZER](s: String?) -> <v0>
|
||||
s <v1>: {<: CharSequence?} NEW: r(s) -> <v1>
|
||||
length <v2>: * NEW: r(length|<v1>) -> <v2>
|
||||
s?.length <v2>: * COPY
|
||||
{ s?.length } <v2>: * COPY
|
||||
<v0>: {<: IntProgression?} NEW: magic[FAKE_INITIALIZER](s: IntProgression?) -> <v0>
|
||||
s <v1>: {<: Progression<Int>?} NEW: r(s) -> <v1>
|
||||
start <v2>: * NEW: r(start|<v1>) -> <v2>
|
||||
s?.start <v2>: * COPY
|
||||
{ s?.start } <v2>: * COPY
|
||||
=====================
|
||||
|
||||
@@ -4,8 +4,8 @@ fun box() : String {
|
||||
val w = object : Comparator<String?> {
|
||||
|
||||
override fun compare(o1 : String?, o2 : String?) : Int {
|
||||
val l1 : Int = o1?.length ?: 0
|
||||
val l2 = o2?.length ?: 0
|
||||
val l1 : Int = o1?.length() ?: 0
|
||||
val l2 = o2?.length() ?: 0
|
||||
return l1 - l2
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ fun box(): String {
|
||||
if (y != 5) return "Fail 2 $y"
|
||||
|
||||
var z = ""
|
||||
do { z += z.length } while (z.length < 5)
|
||||
do { z += z.length() } while (z.length() < 5)
|
||||
if (z != "01234") return "Fail 3 $z"
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -12,7 +12,7 @@ public fun testCoalesce() {
|
||||
else -> "Hello world"
|
||||
}
|
||||
|
||||
printlnMock(value.length)
|
||||
printlnMock(value.length())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -34,7 +34,7 @@ object StringHandler {
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.foo = 42
|
||||
a.foo = a.foo + baz.length
|
||||
a.foo = a.foo + baz.length()
|
||||
a.foo = 239
|
||||
A.bar = baz + a.foo
|
||||
baz + A.bar
|
||||
|
||||
+1
-2
@@ -6,11 +6,10 @@ fun escapeChar(c : Char) : String? = when (c) {
|
||||
}
|
||||
|
||||
tailRecursive fun String.escape(i : Int = 0, result : StringBuilder = StringBuilder()) : String =
|
||||
if (i == length) result.toString()
|
||||
if (i == length()) result.toString()
|
||||
else escape(i + 1, result.append(escapeChar(get(i))))
|
||||
|
||||
fun box() : String {
|
||||
"test me not \\".escape()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,5 +4,5 @@ tailRecursive fun String.repeat(num : Int, acc : StringBuilder = StringBuilder()
|
||||
|
||||
fun box() : String {
|
||||
val s = "a".repeat(10000)
|
||||
return if (s.length == 10000) "OK" else "FAIL: ${s.length}"
|
||||
}
|
||||
return if (s.length() == 10000) "OK" else "FAIL: ${s.length()}"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ fun box(): String {
|
||||
val list = java.util.ArrayList<String>()
|
||||
list.add("0")
|
||||
list[0][0]
|
||||
list[0].length
|
||||
list[0].length()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ fun escapeChar(c : Char) : String? = when (c) {
|
||||
}
|
||||
|
||||
fun String.escape(i : Int = 0, result : String = "") : String =
|
||||
if (i == length) result
|
||||
if (i == length()) result
|
||||
else escape(i + 1, result + escapeChar(get(i)))
|
||||
|
||||
fun box() : String {
|
||||
@@ -19,7 +19,7 @@ fun box() : String {
|
||||
System.out?.println("}");
|
||||
System.out?.println();
|
||||
System.out?.println("fun String.escape(i : Int = 0, result : String = \"\") : String =");
|
||||
System.out?.println(" if (i == length) result");
|
||||
System.out?.println(" if (i == length()) result");
|
||||
System.out?.println(" else escape(i + 1, result + escapeChar(this.get(i)))");
|
||||
System.out?.println();
|
||||
System.out?.println("fun main(args : Array<String>) {");
|
||||
|
||||
@@ -3,7 +3,7 @@ class Test {
|
||||
private val b : String get() = a
|
||||
|
||||
fun outer() : Int {
|
||||
return b.length
|
||||
return b.length()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun t1() : Boolean {
|
||||
val s1 : String? = "sff"
|
||||
val s2 : String? = null
|
||||
return s1?.length == 3 && s2?.length == null
|
||||
return s1?.length() == 3 && s2?.length() == null
|
||||
}
|
||||
|
||||
fun t2() : Boolean {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Thing(delegate: CharSequence) : CharSequence by delegate
|
||||
|
||||
fun box(): String {
|
||||
val l = Thing("hello there").length()
|
||||
return if (l == 11) "OK" else "Fail $l"
|
||||
}
|
||||
@@ -14,7 +14,7 @@ fun box() : String {
|
||||
|
||||
val test5 =
|
||||
"""
|
||||
${s.length}
|
||||
${s.length()}
|
||||
"""
|
||||
if (test5 != "\n 3\n") return "Fail 5: $test5"
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ fun box(): String {
|
||||
|
||||
override fun condition(): Boolean {
|
||||
result = "OK"
|
||||
return result.length == 2
|
||||
return result.length() == 2
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fun box(): String {
|
||||
var v = "FAIL"
|
||||
val max = JavaClass.findMaxAndInvokeCallback({ a, b -> a.length - b.length }, "foo", "kotlin", { v = "OK" })
|
||||
val max = JavaClass.findMaxAndInvokeCallback({ a, b -> a.length() - b.length() }, "foo", "kotlin", { v = "OK" })
|
||||
if (max != "kotlin") return "Wrong max: $max"
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fun box(): String {
|
||||
val wc = WeirdComparator<String>()
|
||||
val result = wc.max({ a, b -> a.length - b.length }, "java", "kotlin")
|
||||
val result = wc.max({ a, b -> a.length() - b.length() }, "java", "kotlin")
|
||||
if (result != "kotlin") return "Wrong: $result"
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
fun box(): String {
|
||||
val result = WeirdComparator.max<String>({ a, b -> a.length - b.length }, "java", "kotlin")
|
||||
val result = WeirdComparator.max<String>({ a, b -> a.length() - b.length() }, "java", "kotlin")
|
||||
if (result != "kotlin") return "Wrong: $result"
|
||||
|
||||
val result2 = WeirdComparator.max2<String>({ a, b -> a.length - b.length }, "java", "kotlin")
|
||||
val result2 = WeirdComparator.max2<String>({ a, b -> a.length() - b.length() }, "java", "kotlin")
|
||||
if (result2 != "kotlin") return "Wrong: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fun box(): String {
|
||||
val wc = WeirdComparator<String>().createInner()!!
|
||||
val result = wc.max({ a, b -> a.length - b.length }, "java", "kotlin")
|
||||
val result = wc.max({ a, b -> a.length() - b.length() }, "java", "kotlin")
|
||||
if (result != "kotlin") return "Wrong: $result"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
fun test1(): Int {
|
||||
val inlineX = Inline()
|
||||
return inlineX.foo({(z: Int) -> "" + z}, 25, {String.() -> this.length})
|
||||
return inlineX.foo({(z: Int) -> "" + z}, 25, {String.() -> this.length()})
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 2) return "test1: ${test1()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package test
|
||||
public class Holder(var value: String = "") {
|
||||
|
||||
public fun plusAssign(s: String?) {
|
||||
if (value.length != 0) {
|
||||
if (value.length() != 0) {
|
||||
value += " -> "
|
||||
}
|
||||
value += s
|
||||
@@ -30,4 +30,4 @@ public inline fun <R> doCallWithException(h: Holder, block: ()-> R) : R {
|
||||
h += "inline fun finally"
|
||||
throw RuntimeException("fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package test
|
||||
public class Holder(var value: String = "") {
|
||||
|
||||
public fun plusAssign(s: String?) {
|
||||
if (value.length != 0) {
|
||||
if (value.length() != 0) {
|
||||
value += " -> "
|
||||
}
|
||||
value += s
|
||||
@@ -30,4 +30,4 @@ public inline fun <R> doCallWithException(h: Holder, block: ()-> R) {
|
||||
h += "inline fun finally"
|
||||
throw RuntimeException("fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package test
|
||||
public class Holder(var value: String = "") {
|
||||
|
||||
public fun plusAssign(s: String?) {
|
||||
if (value.length != 0) {
|
||||
if (value.length() != 0) {
|
||||
value += " -> "
|
||||
}
|
||||
value += s
|
||||
@@ -33,4 +33,4 @@ public inline fun doCall(block: ()-> String, finallyBlock: ()-> String,
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ package a
|
||||
public var topLevel: Int = 42
|
||||
|
||||
public val String.extension: Long
|
||||
get() = length.toLong()
|
||||
get() = length().toLong()
|
||||
|
||||
@@ -4502,7 +4502,7 @@ package java {
|
||||
public open fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.AbstractStringBuilder!
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun length(): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.AbstractStringBuilder!
|
||||
public open fun reverse(): java.lang.AbstractStringBuilder!
|
||||
@@ -8004,7 +8004,7 @@ package java {
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun lastIndexOfSupplementary(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun length(): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open fun matches(/*0*/ p0: kotlin.String!): kotlin.Boolean
|
||||
public open fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun regionMatches(/*0*/ p0: kotlin.Boolean, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!, /*3*/ p3: kotlin.Int, /*4*/ p4: kotlin.Int): kotlin.Boolean
|
||||
@@ -8113,7 +8113,7 @@ package java {
|
||||
public open override /*1*/ fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.StringBuffer!
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open override /*2*/ fun length(): kotlin.Int
|
||||
public open override /*1*/ fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun readObject(/*0*/ p0: java.io.ObjectInputStream!): kotlin.Unit
|
||||
public open override /*1*/ fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.StringBuffer!
|
||||
@@ -8184,7 +8184,7 @@ package java {
|
||||
public open override /*1*/ fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.StringBuilder!
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun readObject(/*0*/ p0: java.io.ObjectInputStream!): kotlin.Unit
|
||||
public open override /*1*/ fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.StringBuilder!
|
||||
|
||||
@@ -14,7 +14,7 @@ fun box() : String {
|
||||
|
||||
val test5 =
|
||||
"""
|
||||
${s.length}
|
||||
${s.length()}
|
||||
"""
|
||||
if (test5 != "\n 3\n") return "Fail 5: $test5"
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package qualified_expressions
|
||||
|
||||
fun test(s: String?) {
|
||||
val <!UNUSED_VARIABLE!>a<!>: Int = <!TYPE_MISMATCH!>s?.length<!>
|
||||
val b: Int? = s?.length
|
||||
val <!UNUSED_VARIABLE!>c<!>: Int = s?.length ?: -11
|
||||
val <!UNUSED_VARIABLE!>d<!>: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
|
||||
val e: String = <!TYPE_MISMATCH!>s?.length<!> ?: "empty"
|
||||
val <!UNUSED_VARIABLE!>f<!>: Int = s?.length ?: b ?: 1
|
||||
fun test(s: IntRange?) {
|
||||
val <!UNUSED_VARIABLE!>a<!>: Int = <!TYPE_MISMATCH!>s?.start<!>
|
||||
val b: Int? = s?.start
|
||||
val <!UNUSED_VARIABLE!>c<!>: Int = s?.start ?: -11
|
||||
val <!UNUSED_VARIABLE!>d<!>: Int = s?.start ?: <!TYPE_MISMATCH!>"empty"<!>
|
||||
val e: String = <!TYPE_MISMATCH!>s?.start<!> ?: "empty"
|
||||
val <!UNUSED_VARIABLE!>f<!>: Int = s?.end ?: b ?: 1
|
||||
val <!UNUSED_VARIABLE!>g<!>: Boolean? = e.startsWith("s")//?.length
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
package qualified_expressions {
|
||||
internal fun test(/*0*/ s: kotlin.String?): kotlin.Unit
|
||||
internal fun test(/*0*/ s: kotlin.IntRange?): kotlin.Unit
|
||||
internal fun kotlin.String.startsWith(/*0*/ s: kotlin.String): kotlin.Boolean
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ internal final class JSub : java.lang.CharSequence {
|
||||
|
||||
internal final class Sub : kotlin.CharSequence {
|
||||
public constructor Sub()
|
||||
public abstract override /*1*/ /*fake_override*/ val length: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fun illegalWhenBlock(a: Any): Int {
|
||||
when(a) {
|
||||
is Int -> return <!DEBUG_INFO_SMARTCAST!>a<!>
|
||||
is String -> return <!DEBUG_INFO_SMARTCAST!>a<!>.length
|
||||
is String -> return <!DEBUG_INFO_SMARTCAST!>a<!>.length()
|
||||
}
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
+2
-3
@@ -6,11 +6,10 @@ fun test(x: Any) {
|
||||
if (y !is String) return
|
||||
class Local {
|
||||
{
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.length
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ fun test(x: Any?) {
|
||||
if (x !is String) return
|
||||
|
||||
class C {
|
||||
val v = <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
val v = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
|
||||
|
||||
val vGet: Int
|
||||
get() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
get() = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
|
||||
|
||||
val s: String = <!DEBUG_INFO_SMARTCAST!>x<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
fun foo(x: Any?) {
|
||||
if (x is String) {
|
||||
object : Base(<!DEBUG_INFO_SMARTCAST!>x<!>) {
|
||||
fun bar() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
fun bar() = <!DEBUG_INFO_SMARTCAST!>x<!>.length()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class Base(s: String)
|
||||
open class Base(s: String)
|
||||
|
||||
@@ -4,9 +4,8 @@ fun test(x: Any) {
|
||||
class LocalOuter {
|
||||
inner class Local {
|
||||
{
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
fun testWhen(t: String?, x: String?): Int {
|
||||
return when {
|
||||
t == null -> 0
|
||||
x == null -> <!DEBUG_INFO_SMARTCAST!>t<!>.length // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if)
|
||||
else -> (<!DEBUG_INFO_SMARTCAST!>t<!> + x).length
|
||||
x == null -> <!DEBUG_INFO_SMARTCAST!>t<!>.length() // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if)
|
||||
else -> (<!DEBUG_INFO_SMARTCAST!>t<!> + x).length()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package n
|
||||
import java.util.*
|
||||
|
||||
fun test() {
|
||||
val foo = arrayList("").map { it -> it.length }.fold(0, { x, y -> Math.max(x, y) })
|
||||
val foo = arrayList("").map { it -> it.length() }.fold(0, { x, y -> Math.max(x, y) })
|
||||
foo : Int
|
||||
<!TYPE_MISMATCH!>foo<!> : String
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit { for (element in this)
|
||||
fun bar(operation: (String) -> Unit) = operation("")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
args.forEach { (a : String) : Unit -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { (a) : Unit -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { (a : String) -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { a -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { it.length } // This works!
|
||||
args.forEach { (a : String) : Unit -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { (a) : Unit -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { (a : String) -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { a -> a.length() } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { it.length() } // This works!
|
||||
|
||||
bar { (a: String) : Unit -> a.length }
|
||||
bar { (a) : Unit -> a.length }
|
||||
bar { (a: String) -> a.length }
|
||||
bar { a -> a.length }
|
||||
bar { it.length }
|
||||
bar { (a: String) : Unit -> a.length() }
|
||||
bar { (a) : Unit -> a.length() }
|
||||
bar { (a: String) -> a.length() }
|
||||
bar { a -> a.length() }
|
||||
bar { it.length() }
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.*
|
||||
|
||||
fun foo(lines: List<String>) {
|
||||
val w = max(lines, comparator {o1, o2 ->
|
||||
val l1 : Int = o1.length // Types of o1 and o2 are ERROR
|
||||
val l2 = o2.length
|
||||
val l1 : Int = o1.length() // Types of o1 and o2 are ERROR
|
||||
val l2 = o2.length()
|
||||
l1 - l2
|
||||
}).sure()
|
||||
w : String
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
inline fun foo(bar1: (String.() -> Int) -> Int, bar2: (()->Int) -> Int) {
|
||||
bar1 @label {
|
||||
this@label.length
|
||||
this@label.length()
|
||||
}
|
||||
|
||||
bar1 {
|
||||
this.length
|
||||
this.length()
|
||||
}
|
||||
//unmute after KT-4247 fix
|
||||
//bar1 {
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ public class Y extends X<String> {
|
||||
// FILE: test.kt
|
||||
|
||||
fun main() {
|
||||
Y().foo().length
|
||||
Y().foo().length()
|
||||
Y().bar(null)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
fun f(c: String): Int {
|
||||
return c.<!FUNCTION_EXPECTED!>length<!>()
|
||||
fun f(c: LongRange): Int {
|
||||
return c.<!FUNCTION_EXPECTED!>start<!>()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun f(/*0*/ c: kotlin.String): kotlin.Int
|
||||
internal fun f(/*0*/ c: kotlin.LongRange): kotlin.Int
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
fun foo(bar1: (String.() -> Int) -> Int) {
|
||||
bar1 {
|
||||
this.length
|
||||
this.length()
|
||||
}
|
||||
|
||||
bar1 {
|
||||
this@bar1.length
|
||||
this@bar1.length()
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,18 @@ package kt244
|
||||
|
||||
fun f(s: String?) {
|
||||
if (s != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>s<!>.length //ok
|
||||
var <!UNUSED_VARIABLE!>i<!> = <!DEBUG_INFO_SMARTCAST!>s<!>.length //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(<!DEBUG_INFO_SMARTCAST!>s<!>.length) //error
|
||||
<!DEBUG_INFO_SMARTCAST!>s<!>.length() //ok
|
||||
var <!UNUSED_VARIABLE!>i<!> = <!DEBUG_INFO_SMARTCAST!>s<!>.length() //error: Only safe calls are allowed on a nullable receiver
|
||||
System.out.println(<!DEBUG_INFO_SMARTCAST!>s<!>.length()) //error
|
||||
}
|
||||
}
|
||||
|
||||
// more tests
|
||||
class A(a: String?) {
|
||||
val b = if (a != null) <!DEBUG_INFO_SMARTCAST!>a<!>.length else 1
|
||||
val b = if (a != null) <!DEBUG_INFO_SMARTCAST!>a<!>.length() else 1
|
||||
{
|
||||
if (a != null) {
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.length
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!DEBUG_INFO_SMARTCAST!>a<!>.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class A(a: String?) {
|
||||
|
||||
{
|
||||
if (a is String) {
|
||||
i = <!DEBUG_INFO_SMARTCAST!>a<!>.length
|
||||
i = <!DEBUG_INFO_SMARTCAST!>a<!>.length()
|
||||
}
|
||||
else {
|
||||
i = 3
|
||||
|
||||
@@ -19,8 +19,8 @@ fun test(j: J) {
|
||||
j.j()!!.j()
|
||||
|
||||
val ann = j.foo<String>()
|
||||
ann!!.length
|
||||
ann.length
|
||||
ann!!.length()
|
||||
ann.length()
|
||||
|
||||
val a = j.foo<J>()
|
||||
a!!.j()
|
||||
|
||||
@@ -12,5 +12,5 @@ public class J {
|
||||
import p.*
|
||||
|
||||
fun test(j: J) {
|
||||
j.s()?.length ?: ""
|
||||
}
|
||||
j.s()?.length() ?: ""
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ fun foo() {
|
||||
val list = ArrayList<String?>()
|
||||
|
||||
for (s in list) {
|
||||
s<!UNSAFE_CALL!>.<!>length
|
||||
s<!UNSAFE_CALL!>.<!>length()
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,5 @@ public class J {
|
||||
import p.*
|
||||
|
||||
fun test(j: J) {
|
||||
j.s()?.length.checkType { it : _<Int?> }
|
||||
}
|
||||
j.s()?.length().checkType { it : _<Int?> }
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
fun foo(i: Int) {}
|
||||
|
||||
fun test(s: String?) {
|
||||
foo(<!TYPE_MISMATCH!>s?.length<!>)
|
||||
}
|
||||
foo(<!TYPE_MISMATCH!>s?.length()<!>)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package kt939
|
||||
|
||||
|
||||
//KT-939 CommonSupertypes erases scopes associated to types
|
||||
|
||||
fun compare(o1 : String?, o2 : String?) : Int {
|
||||
val l1 = o1?.length ?: 0
|
||||
val l2 = o2?.length ?: 0
|
||||
val l1 = o1?.length() ?: 0
|
||||
val l2 = o2?.length() ?: 0
|
||||
return l1 - l2 // '-' is unresolved, because the type of l1 is Int with an empty member scope
|
||||
}
|
||||
|
||||
//KT-1117 Unresolved reference to multiply sign
|
||||
|
||||
fun test() {
|
||||
(System.getProperty("path.separator")?.length ?: 4) * 55 + 5
|
||||
(System.getProperty("path.separator")?.length() ?: 4) * 55 + 5
|
||||
|
||||
val x = System.getProperty("path.separator")?.length ?: 4
|
||||
val x = System.getProperty("path.separator")?.length() ?: 4
|
||||
x * 55 + 5
|
||||
}
|
||||
|
||||
@@ -4507,7 +4507,7 @@ package java {
|
||||
public open fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.AbstractStringBuilder!
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun length(): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.AbstractStringBuilder!
|
||||
public open fun reverse(): java.lang.AbstractStringBuilder!
|
||||
@@ -8009,7 +8009,7 @@ package java {
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun lastIndexOfSupplementary(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun length(): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open fun matches(/*0*/ p0: kotlin.String!): kotlin.Boolean
|
||||
public open fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open fun regionMatches(/*0*/ p0: kotlin.Boolean, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!, /*3*/ p3: kotlin.Int, /*4*/ p4: kotlin.Int): kotlin.Boolean
|
||||
@@ -8118,7 +8118,7 @@ package java {
|
||||
public open override /*1*/ fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.StringBuffer!
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public open override /*2*/ fun length(): kotlin.Int
|
||||
public open override /*1*/ fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun readObject(/*0*/ p0: java.io.ObjectInputStream!): kotlin.Unit
|
||||
public open override /*1*/ fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.StringBuffer!
|
||||
@@ -8189,7 +8189,7 @@ package java {
|
||||
public open override /*1*/ fun insert(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.String!): java.lang.StringBuilder!
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!): kotlin.Int
|
||||
public open override /*1*/ fun lastIndexOf(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun offsetByCodePoints(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int): kotlin.Int
|
||||
private open fun readObject(/*0*/ p0: java.io.ObjectInputStream!): kotlin.Unit
|
||||
public open override /*1*/ fun replace(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.String!): java.lang.StringBuilder!
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
fun dispatch(request: Request) {
|
||||
val <!UNUSED_VARIABLE!>url<!> = request.getRequestURI() as String
|
||||
|
||||
if (request.getMethod()?.length != 0) {
|
||||
if (request.getMethod()?.length() != 0) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
fun foo(p1: String?, p2: String?) {
|
||||
if (p2 != null) {
|
||||
val v = p1 ?: <!DEBUG_INFO_SMARTCAST!>p2<!>
|
||||
val size = v.length
|
||||
val size = v.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//KT-5455 Need warning about redundant type cast
|
||||
fun foo(o: Any): Int {
|
||||
if (o is String) {
|
||||
return (o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String).length
|
||||
return (o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String).length()
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -33,3 +33,6 @@ val prop9 = "a" + "b"
|
||||
|
||||
// val prop10: \"abb\"
|
||||
val prop10 = prop9 + "b"
|
||||
|
||||
// val prop11: 6
|
||||
val prop11 = "kotlin".length()
|
||||
|
||||
@@ -6286,6 +6286,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt3571.kt")
|
||||
public void testKt3571() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/strings/kt3571.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt3652.kt")
|
||||
public void testKt3652() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/strings/kt3652.kt");
|
||||
|
||||
@@ -19,5 +19,5 @@ package kotlin
|
||||
public trait CharSequence {
|
||||
public fun get(index: Int): Char
|
||||
|
||||
public val length: Int
|
||||
public fun length(): Int
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public class String : Comparable<String>, CharSequence {
|
||||
public fun plus(other: Any?): String
|
||||
|
||||
public override fun compareTo(other: String): Int
|
||||
|
||||
public override fun get(index: Int): Char
|
||||
public override val length: Int
|
||||
|
||||
public override fun length(): Int
|
||||
}
|
||||
|
||||
+4
-4
@@ -95,8 +95,8 @@ private fun mapJavaClassToKotlin(name: String): String {
|
||||
}
|
||||
}
|
||||
if (name[0] == '[') {
|
||||
val element = (name as java.lang.String).substring(1)
|
||||
return when (element[0]) {
|
||||
val element = (name as java.lang.String).substring(1) as java.lang.String
|
||||
return when (element.charAt(0)) {
|
||||
'Z' -> "kotlin.BooleanArray"
|
||||
'C' -> "kotlin.CharArray"
|
||||
'B' -> "kotlin.ByteArray"
|
||||
@@ -105,8 +105,8 @@ private fun mapJavaClassToKotlin(name: String): String {
|
||||
'F' -> "kotlin.FloatArray"
|
||||
'J' -> "kotlin.LongArray"
|
||||
'D' -> "kotlin.DoubleArray"
|
||||
'L' -> "kotlin.Array<${mapJavaClassToKotlin((element as java.lang.String).substring(1, element.length() - 1))}>"
|
||||
else -> "kotlin.Array<${mapJavaClassToKotlin(element)}>"
|
||||
'L' -> "kotlin.Array<${mapJavaClassToKotlin(element.substring(1, element.length() - 1))}>"
|
||||
else -> "kotlin.Array<${mapJavaClassToKotlin(element as kotlin.String)}>"
|
||||
}
|
||||
}
|
||||
return name
|
||||
|
||||
@@ -24,7 +24,7 @@ suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
private fun String.capitalizeWithJavaBeanConvention(): String {
|
||||
// The code is a bit crooked because otherwise there are overload resolution ambiguities caused by the fact
|
||||
// that we compile it with the built-ins both in source and as a compiled library
|
||||
val l = length
|
||||
val l = length()
|
||||
if (l > 1 && Character.isUpperCase(get(1))) return this
|
||||
val first = get(0)
|
||||
this as java.lang.String
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package qualified_expressions
|
||||
|
||||
fun test(s: String?) {
|
||||
val <warning>a</warning>: Int = <error>s?.length</error>
|
||||
val b: Int? = s?.length
|
||||
val <warning>c</warning>: Int = s?.length ?: -11
|
||||
val <warning>d</warning>: Int = s?.length ?: <error>"empty"</error>
|
||||
val e: String = <error>s?.length</error> ?: "empty"
|
||||
val <warning>f</warning>: Int = s?.length ?: b ?: 1
|
||||
fun test(s: IntRange?) {
|
||||
val <warning>a</warning>: Int = <error>s?.start</error>
|
||||
val b: Int? = s?.start
|
||||
val <warning>c</warning>: Int = s?.start ?: -11
|
||||
val <warning>d</warning>: Int = s?.start ?: <error>"empty"</error>
|
||||
val e: String = <error>s?.start</error> ?: "empty"
|
||||
val <warning>f</warning>: Int = s?.end ?: b ?: 1
|
||||
val <warning>g</warning>: Boolean? = e.startsWith("s")//?.length
|
||||
}
|
||||
|
||||
fun String.startsWith(<warning>s</warning>: String): Boolean = true
|
||||
fun String.startsWith(<warning>s</warning>: String): Boolean = true
|
||||
|
||||
@@ -9,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(<error>expr</error>)
|
||||
if (c >= '0' && c <= '9') {
|
||||
val n = c - '0'
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package jet121
|
||||
fun box() : String {
|
||||
val answer = apply("OK") { String.() : Int ->
|
||||
get(0)
|
||||
length
|
||||
|
||||
fun box(): String {
|
||||
val answer = apply("OK") { String.(): Int ->
|
||||
get(0)
|
||||
length()
|
||||
}
|
||||
|
||||
return if (answer == 2) "OK" else "FAIL"
|
||||
}
|
||||
}
|
||||
|
||||
fun apply(arg:String, f : String.() -> Int) : Int {
|
||||
return arg.f()
|
||||
}
|
||||
fun apply(arg: String, f: String.() -> Int): Int {
|
||||
return arg.f()
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ fun main(args: Array<String>) {
|
||||
val foo: String? = "abc"
|
||||
if (foo != null<caret>) {
|
||||
doSomething ("Hello")
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ fun main(args: Array<String>) {
|
||||
var foo: String? = "foo"
|
||||
var bar: String? = "bar"
|
||||
if (foo != null<caret>) {
|
||||
bar?.length
|
||||
bar?.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
fun main(args: Array<String>) {
|
||||
val foo = "foo"
|
||||
if (null == <caret>null) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ fun <T> T.compareTo(a: T): Int = 0
|
||||
fun main(args: Array<String>) {
|
||||
val foo = "foo"
|
||||
if (foo > null<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ fun String?.times(a: Int): Boolean = a == 0
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String = "foo"
|
||||
if (foo * 10<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
doSomething(foo)
|
||||
if (foo != null<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else {
|
||||
null
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ fun doSomething<T>(a: T) {}
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
doSomething(foo)
|
||||
foo?.length
|
||||
foo?.length()
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ val x = maybeFoo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (x !=<caret> null) {
|
||||
x.length
|
||||
x.length()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ fun maybeFoo(): String? {
|
||||
val x = maybeFoo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
x?.length
|
||||
x?.length()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
fun main(args: Array<String>) {
|
||||
val foo = "foo"
|
||||
if (<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun maybeFoo(): String? {
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (foo != null<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ fun main(args: Array<String>) {
|
||||
if (foo == null<caret>) {
|
||||
}
|
||||
else {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun maybeFoo(): String? {
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (foo != null<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
else {
|
||||
null
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun maybeFoo(): String? {
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (foo != null<caret>)
|
||||
foo.length
|
||||
foo.length()
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ fun main(args: Array<String>) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = maybeFoo()?.length
|
||||
val x = maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ fun main(args: Array<String>) {
|
||||
if (foo == null<caret>)
|
||||
null
|
||||
else
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun maybeFoo(): String? {
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (foo != null<caret>)
|
||||
foo.length
|
||||
foo.length()
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
if<caret> {
|
||||
foo.length
|
||||
foo.length()
|
||||
} else null
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ fun maybeFoo(): String? {
|
||||
fun main(args: Array<String>) {
|
||||
val foo = maybeFoo()
|
||||
if (foo != null<caret>) {
|
||||
foo.length
|
||||
foo.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ fun maybeFoo(): String? {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
maybeFoo()?.length
|
||||
maybeFoo()?.length()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ fun main(args: Array<String>) {
|
||||
val foo: String? = "foo"
|
||||
val bar: String? = null
|
||||
if (foo == bar<caret>) {
|
||||
foo?.length
|
||||
foo?.length()
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user