Add toString() to Any, fix all tests

#KT-4517 Fixed
This commit is contained in:
Alexander Udalov
2014-02-06 23:43:12 +04:00
parent 6127d53eac
commit 3dcd85bdb4
55 changed files with 110 additions and 72 deletions
@@ -100,6 +100,7 @@ public class IntrinsicMethods {
declareIntrinsicFunction(typeName, Name.identifier("dec"), 0, DEC);
declareIntrinsicFunction(typeName, Name.identifier("hashCode"), 0, HASH_CODE);
declareIntrinsicFunction(typeName, Name.identifier("equals"), 1, EQUALS);
declareIntrinsicFunction(typeName, Name.identifier("toString"), 0, TO_STRING);
}
declareBinaryOp(Name.identifier("plus"), IADD);
@@ -116,6 +117,7 @@ public class IntrinsicMethods {
declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("not"), 0, new Not());
declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("equals"), 1, EQUALS);
declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("toString"), 0, TO_STRING);
declareIntrinsicFunction(Name.identifier("String"), Name.identifier("plus"), 1, new Concat());
declareIntrinsicFunction(Name.identifier("CharSequence"), Name.identifier("get"), 1, new StringGetChar());
@@ -30,7 +30,8 @@ class JavaToKotlinMethodMapGenerated {
put(b, "java.lang.Object", "Any",
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
pair("hashCode()", "fun hashCode(): jet.Int")
pair("hashCode()", "fun hashCode(): jet.Int"),
pair("toString()", "fun toString(): jet.String")
);
put(b, "java.lang.String", "String",
@@ -47,7 +48,8 @@ class JavaToKotlinMethodMapGenerated {
put(b, "java.lang.Throwable", "Throwable",
pair("getCause()", "fun getCause(): jet.Throwable?"),
pair("getMessage()", "fun getMessage(): jet.String?"),
pair("printStackTrace()", "fun printStackTrace(): jet.Unit")
pair("printStackTrace()", "fun printStackTrace(): jet.Unit"),
pair("toString()", "fun toString(): jet.String")
);
put(b, "java.lang.Comparable", "Comparable",
@@ -58,12 +60,14 @@ class JavaToKotlinMethodMapGenerated {
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
pair("hashCode()", "fun hashCode(): jet.Int"),
pair("name()", "fun name(): jet.String"),
pair("ordinal()", "fun ordinal(): jet.Int")
pair("ordinal()", "fun ordinal(): jet.Int"),
pair("toString()", "fun toString(): jet.String")
);
put(b, "java.lang.annotation.Annotation", "Annotation",
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
pair("hashCode()", "fun hashCode(): jet.Int")
pair("hashCode()", "fun hashCode(): jet.Int"),
pair("toString()", "fun toString(): jet.String")
);
put(b, "java.lang.Iterable", "Iterable",
@@ -27,6 +27,7 @@ private val emptyUnaryFun: Function1<Long, Long> = { a -> 1.toLong() }
private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>
= hashMapOf<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>(
unaryOperation(BOOLEAN, "not", { a -> a.not() }, emptyUnaryFun),
unaryOperation(BOOLEAN, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(BYTE, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(BYTE, "minus", { a -> a.minus() }, { a -> a.minus() }),
unaryOperation(BYTE, "toChar", { a -> a.toChar() }, emptyUnaryFun),
@@ -36,6 +37,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(BYTE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun),
unaryOperation(BYTE, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(BYTE, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(BYTE, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(CHAR, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(CHAR, "minus", { a -> a.minus() }, emptyUnaryFun),
unaryOperation(CHAR, "toChar", { a -> a.toChar() }, emptyUnaryFun),
@@ -45,6 +47,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(CHAR, "toFloat", { a -> a.toFloat() }, emptyUnaryFun),
unaryOperation(CHAR, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(CHAR, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(CHAR, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(DOUBLE, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(DOUBLE, "minus", { a -> a.minus() }, emptyUnaryFun),
unaryOperation(DOUBLE, "toChar", { a -> a.toChar() }, emptyUnaryFun),
@@ -54,6 +57,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(DOUBLE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun),
unaryOperation(DOUBLE, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(DOUBLE, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(DOUBLE, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(FLOAT, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(FLOAT, "minus", { a -> a.minus() }, emptyUnaryFun),
unaryOperation(FLOAT, "toChar", { a -> a.toChar() }, emptyUnaryFun),
@@ -63,6 +67,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(FLOAT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun),
unaryOperation(FLOAT, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(FLOAT, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(FLOAT, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(INT, "inv", { a -> a.inv() }, emptyUnaryFun),
unaryOperation(INT, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(INT, "minus", { a -> a.minus() }, { a -> a.minus() }),
@@ -73,6 +78,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(INT, "toDouble", { a -> a.toDouble() }, emptyUnaryFun),
unaryOperation(INT, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(INT, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(INT, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(LONG, "inv", { a -> a.inv() }, emptyUnaryFun),
unaryOperation(LONG, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(LONG, "minus", { a -> a.minus() }, { a -> a.minus() }),
@@ -83,6 +89,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(LONG, "toDouble", { a -> a.toDouble() }, emptyUnaryFun),
unaryOperation(LONG, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(LONG, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(LONG, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(SHORT, "toInt", { a -> a.toInt() }, emptyUnaryFun),
unaryOperation(SHORT, "minus", { a -> a.minus() }, { a -> a.minus() }),
unaryOperation(SHORT, "toChar", { a -> a.toChar() }, emptyUnaryFun),
@@ -92,6 +99,7 @@ private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
unaryOperation(SHORT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun),
unaryOperation(SHORT, "toShort", { a -> a.toShort() }, emptyUnaryFun),
unaryOperation(SHORT, "toByte", { a -> a.toByte() }, emptyUnaryFun),
unaryOperation(SHORT, "toString", { a -> a.toString() }, emptyUnaryFun),
unaryOperation(STRING, "toString", { a -> a.toString() }, emptyUnaryFun)
)
@@ -1,6 +1,6 @@
trait Trait {
fun foo() = "O"
fun toString() = "K"
override fun toString() = "K"
}
class SimpleClass : Trait
@@ -1,5 +1,5 @@
class mInt(val i : Int) {
fun toString() : String = "mint: $i"
override fun toString() : String = "mint: $i"
fun plus(i : Int) = mInt(this.i + i)
fun inc() = mInt(i + 1)
}
@@ -5,7 +5,7 @@ class MyString {
return this
}
fun toString(): String {
override fun toString(): String {
return s
}
}
@@ -5,7 +5,7 @@ class MyString {
return this
}
fun toString(): String {
override fun toString(): String {
return s
}
}
@@ -7,7 +7,7 @@ class MyString {
return this
}
fun toString(): String {
override fun toString(): String {
return s
}
}
@@ -7,7 +7,7 @@ class MyString {
return this
}
fun toString(): String {
override fun toString(): String {
return s
}
}
@@ -3,7 +3,7 @@ class A {
{
a = object {
fun toString(): String = "OK"
override fun toString(): String = "OK"
}.toString()
}
}
@@ -1,6 +1,6 @@
class A(
val a: String = object {
fun toString(): String = "OK"
override fun toString(): String = "OK"
}.toString()
)
@@ -3,7 +3,7 @@ package pack
open class A(val value: String )
class B(value: String) : A(value) {
fun toString() = "B($value)";
override fun toString() = "B($value)";
}
fun box() = if (B("4").toString() == "B(4)") "OK" else "fail"
@@ -7,7 +7,7 @@ class JsonArray {
}
class ProjectInfo {
public fun toString(): String = "OK"
override fun toString(): String = "OK"
}
public trait Parser<in IN: Any, out OUT: Any> {
@@ -4,7 +4,7 @@ trait Trait : Base {
private val value : String
get() = "OK"
fun toString() = object {
override fun toString() = object {
fun foo() = value
}.foo()
}
@@ -1,5 +1,5 @@
data class A(val x: Int) {
fun toString(): String = "!"
override fun toString(): String = "!"
}
fun box(): String {
@@ -1,5 +1,5 @@
trait SuperTrait {
public fun toString(): String = "!"
override fun toString(): String = "!"
}
data class A(val x: Int): SuperTrait {
@@ -6,7 +6,7 @@ import java.util.ArrayList
public class User(val firstName: String,
val lastName: String,
val age: Int) {
fun toString() = "$firstName $lastName, age $age"
override fun toString() = "$firstName $lastName, age $age"
}
public fun <T: Comparable<T>> Collection<T>.testMin(): T? {
@@ -1,4 +1,4 @@
class A(private var v1: String) {
private var v2 = v1
fun toString(): String { return "A[v1=$v1,v2=$v2]" }
override fun toString(): String { return "A[v1=$v1,v2=$v2]" }
}
@@ -52,7 +52,7 @@ fun main(args : Array<String>) {
trait Element {
fun render(builder : StringBuilder, indent : String)
fun toString() : String? {
override fun toString() : String {
val builder = StringBuilder()
render(builder, "")
return builder.toString()
@@ -183,7 +183,7 @@ fun returnFunctionLiteral(a: Any?): Function0<Int> =
fun mergeAutocasts(a: Any?) {
if (a is String || a is Int) {
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
a.toString()
<!DEBUG_INFO_AUTOCAST!>a<!>.toString()
}
if (a is Int || a is String) {
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
@@ -1,3 +1,3 @@
class Test(private val a: Int b: Int private val c: Int) {
fun toString() = "$a $c"
override fun toString() = "$a $c"
}
@@ -53,6 +53,9 @@ JetFile: MissingCommaInConstructorValueParameterList.kt
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
MODIFIER_LIST
PsiElement(override)('override')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('toString')
@@ -52,33 +52,44 @@ Trait:ClassDescriptorWithResolutionScopes
a:ValueParameterDescriptor
fake <class-object-for-Class>.equals:SimpleFunctionDescriptor
fake <class-object-for-Class>.hashCode:SimpleFunctionDescriptor
fake <class-object-for-Class>.toString:SimpleFunctionDescriptor
fake <class-object-for-NestedClass>.equals:SimpleFunctionDescriptor
fake <class-object-for-NestedClass>.hashCode:SimpleFunctionDescriptor
fake <class-object-for-NestedClass>.toString:SimpleFunctionDescriptor
fake <class-object-for-NestedObject>.equals:SimpleFunctionDescriptor
fake <class-object-for-NestedObject>.hashCode:SimpleFunctionDescriptor
fake <class-object-for-NestedObject>.nestedFunc:SimpleFunctionDescriptor
fake <class-object-for-NestedObject>.toString:SimpleFunctionDescriptor
fake <class-object-for-Object>.<get-objProp>:PropertyGetterDescriptor
fake <class-object-for-Object>.equals:SimpleFunctionDescriptor
fake <class-object-for-Object>.hashCode:SimpleFunctionDescriptor
fake <class-object-for-Object>.objFunc:SimpleFunctionDescriptor
fake <class-object-for-Object>.objProp:PropertyDescriptor
fake <class-object-for-Object>.toString:SimpleFunctionDescriptor
fake Class.<get-traitProp>:PropertyGetterDescriptor
fake Class.equals:SimpleFunctionDescriptor
fake Class.hashCode:SimpleFunctionDescriptor
fake Class.toString:SimpleFunctionDescriptor
fake Class.traitFunc:SimpleFunctionDescriptor
fake Class.traitProp:PropertyDescriptor
fake NestedClass.equals:SimpleFunctionDescriptor
fake NestedClass.hashCode:SimpleFunctionDescriptor
fake NestedClass.toString:SimpleFunctionDescriptor
fake NestedObject.equals:SimpleFunctionDescriptor
fake NestedObject.hashCode:SimpleFunctionDescriptor
fake NestedObject.toString:SimpleFunctionDescriptor
fake NestedTrait.equals:SimpleFunctionDescriptor
fake NestedTrait.hashCode:SimpleFunctionDescriptor
fake NestedTrait.toString:SimpleFunctionDescriptor
fake Object.equals:SimpleFunctionDescriptor
fake Object.hashCode:SimpleFunctionDescriptor
fake Object.toString:SimpleFunctionDescriptor
fake Outer.equals:SimpleFunctionDescriptor
fake Outer.hashCode:SimpleFunctionDescriptor
fake Outer.toString:SimpleFunctionDescriptor
fake Trait.equals:SimpleFunctionDescriptor
fake Trait.hashCode:SimpleFunctionDescriptor
fake Trait.toString:SimpleFunctionDescriptor
func.this:ReceiverParameterDescriptor
innerTest.<get-prop>:PropertyGetterDescriptor
innerTest.<get-propVar>:PropertyGetterDescriptor