Fix tests: "infix modifier required" and "operator modifier required" errors
This commit is contained in:
@@ -4,7 +4,7 @@ package foo
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object NumberDecrypter {
|
||||
fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
|
||||
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
|
||||
"four" -> 4
|
||||
"two" -> 2
|
||||
else -> throw Exception()
|
||||
|
||||
+2
-2
@@ -6,11 +6,11 @@ import kotlin.reflect.KProperty
|
||||
object Delegate {
|
||||
var value = "lol"
|
||||
|
||||
fun getValue(instance: Any?, data: KProperty<*>): String {
|
||||
operator fun getValue(instance: Any?, data: KProperty<*>): String {
|
||||
return value
|
||||
}
|
||||
|
||||
fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
|
||||
operator fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ val String.id: String
|
||||
fun box(): String {
|
||||
val pr = String::id
|
||||
|
||||
if (pr["123"] != "123") return "Fail value: ${pr["123"]}"
|
||||
if (pr.get("123") != "123") return "Fail value: ${pr.get("123")}"
|
||||
|
||||
if (pr.name != "id") return "Fail name: ${pr.name}"
|
||||
|
||||
|
||||
+2
-2
@@ -13,9 +13,9 @@ var Int.foo: Int
|
||||
|
||||
fun box(): String {
|
||||
val pr = Int::foo
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr[42]}"
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr.get(42)}"
|
||||
pr.set(200, 39)
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr[-239]}"
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr.get(-239)}"
|
||||
if (storage != 239) return "Fail 3: $storage"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ fun box(): String {
|
||||
val o = Box("lorem")
|
||||
val prop = Box::value
|
||||
|
||||
if (prop.get(o) != "lorem") return "Fail 1: ${prop[o]}"
|
||||
if (prop.get(o) != "lorem") return "Fail 1: ${prop.get(o)}"
|
||||
prop.set(o, "ipsum")
|
||||
if (prop.get(o) != "ipsum") return "Fail 2: ${prop[o]}"
|
||||
if (prop.get(o) != "ipsum") return "Fail 2: ${prop.get(o)}"
|
||||
if (o.value != "ipsum") return "Fail 3: ${o.value}"
|
||||
o.value = "dolor"
|
||||
if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}"
|
||||
|
||||
+2
-2
@@ -10,12 +10,12 @@ fun format(event: String, property: String, value: Int): String
|
||||
object LoggerDelegate {
|
||||
var log = ""
|
||||
|
||||
fun getValue(state: State, desc: KProperty<*>): Int {
|
||||
operator fun getValue(state: State, desc: KProperty<*>): Int {
|
||||
log += format("get", desc.name, state.realValue)
|
||||
return state.realValue
|
||||
}
|
||||
|
||||
fun setValue(state: State, desc: KProperty<*>, value: Int) {
|
||||
operator fun setValue(state: State, desc: KProperty<*>, value: Int) {
|
||||
log += format("set", desc.name, value)
|
||||
state.realValue = value
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import kotlin.reflect.KProperty
|
||||
class Delegate {
|
||||
}
|
||||
|
||||
fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
operator fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
|
||||
class A {
|
||||
val prop: Int by Delegate()
|
||||
|
||||
@@ -7,10 +7,10 @@ interface WithName {
|
||||
}
|
||||
|
||||
class GetPropertyName() {
|
||||
fun getValue(withName: WithName, property: KProperty<*>): String {
|
||||
operator fun getValue(withName: WithName, property: KProperty<*>): String {
|
||||
return withName.name + ":" + property.name;
|
||||
}
|
||||
fun setValue(withName: WithName, property: KProperty<*>, value: String) {
|
||||
operator fun setValue(withName: WithName, property: KProperty<*>, value: String) {
|
||||
withName.name = value + ":" + property.name
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
}
|
||||
|
||||
fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
operator fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ interface WithNumber {
|
||||
}
|
||||
|
||||
class IncNumber(val inc: Int) {
|
||||
fun getValue(withNumber: WithNumber, property: KProperty<*>): Int {
|
||||
operator fun getValue(withNumber: WithNumber, property: KProperty<*>): Int {
|
||||
return withNumber.number + inc;
|
||||
}
|
||||
fun setValue(withNumber: WithNumber, property: KProperty<*>, value: Int) {
|
||||
operator fun setValue(withNumber: WithNumber, property: KProperty<*>, value: Int) {
|
||||
withNumber.number = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
}
|
||||
|
||||
val prop: Int by Delegate()
|
||||
|
||||
@@ -4,8 +4,8 @@ import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ interface Getter<T> {
|
||||
|
||||
class Delegate<T>(val getter: Getter<T>) {
|
||||
var t: T? = null
|
||||
fun getValue(obj: Any, property: KProperty<*>): T {
|
||||
operator fun getValue(obj: Any, property: KProperty<*>): T {
|
||||
if (t != null) {
|
||||
return t!!
|
||||
}
|
||||
return getter.get()
|
||||
}
|
||||
fun setValue(obj: Any, property: KProperty<*>, value: T) {
|
||||
operator fun setValue(obj: Any, property: KProperty<*>, value: T) {
|
||||
t = value
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ interface Base {
|
||||
}
|
||||
|
||||
class Delegate(val multiplier: Int) {
|
||||
fun getValue(state: State, desc: KProperty<*>): Int = multiplier * state.value
|
||||
operator fun getValue(state: State, desc: KProperty<*>): Int = multiplier * state.value
|
||||
|
||||
fun setValue(state: State, desc: KProperty<*>, value: Int) {
|
||||
operator fun setValue(state: State, desc: KProperty<*>, value: Int) {
|
||||
state.value = value / multiplier
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,6 @@ fun box(): String {
|
||||
testTrue { a.equals(12) }
|
||||
testFalse { a.equals("12") }
|
||||
|
||||
testFalse { a equals 34 }
|
||||
testFalse { a equals "34" }
|
||||
testTrue { a equals 12 }
|
||||
testFalse { a equals "12" }
|
||||
|
||||
val ff: dynamic = f
|
||||
testFalse { ff.equals(v) }
|
||||
assertTrue(f.equalsCalled, "f.equalsCalled")
|
||||
|
||||
@@ -7,7 +7,7 @@ class ArrayWrapper<T>() {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
operator fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(b.contents)
|
||||
|
||||
@@ -7,7 +7,7 @@ class ArrayWrapper<T>() {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
operator fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
contents.addAll(rhs.contents)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class ArrayWrapper<T>() {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
operator fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(rhs.contents)
|
||||
|
||||
@@ -7,7 +7,7 @@ class ArrayWrapper<T>() {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun minus(): ArrayWrapper<T> {
|
||||
operator fun unaryMinus(): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
var i = contents.size();
|
||||
@@ -17,7 +17,7 @@ class ArrayWrapper<T>() {
|
||||
return result
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
operator fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
package foo
|
||||
|
||||
class A(val value: Int) : Comparable<A> {
|
||||
override public fun compareTo(other: A): Int = other.value compareTo value
|
||||
override public fun compareTo(other: A): Int = other.value.compareTo(value)
|
||||
}
|
||||
|
||||
class B(val value: Int)
|
||||
|
||||
fun testExtensionFunctionAsCompareTo() {
|
||||
val compareTo: B.( B ) -> Int = { other -> other.value compareTo this.value }
|
||||
val compareTo: B.( B ) -> Int = { other -> other.value.compareTo(this.value) }
|
||||
|
||||
val x: B = B(100)
|
||||
val y: B = B(200)
|
||||
|
||||
assertEquals(false, x < y, "ext fun: x < y")
|
||||
assertEquals(true, x > y, "ext fun: x > y")
|
||||
assertEquals(1, x compareTo y, "ext fun: x compareTo y")
|
||||
assertEquals(1, x.compareTo(y), "ext fun: x compareTo y")
|
||||
}
|
||||
|
||||
fun testMethodAsCompareTo() {
|
||||
@@ -23,12 +23,12 @@ fun testMethodAsCompareTo() {
|
||||
|
||||
assertEquals(false, x < y, "meth: x < y")
|
||||
assertEquals(true, x > y, "meth: x > y")
|
||||
assertEquals(1, x compareTo y, "meth: x compareTo y")
|
||||
assertEquals(1, x.compareTo(y), "meth: x compareTo y")
|
||||
|
||||
val comparable: Comparable<A> = x
|
||||
assertEquals(false, comparable < y, "meth: (x: Comparable<A>) < y")
|
||||
assertEquals(true, comparable > y, "meth: (x: Comparable<A>) > y")
|
||||
assertEquals(1, comparable compareTo y, "meth: (x: Comparable<A>) compareTo y")
|
||||
assertEquals(1, comparable.compareTo(y), "meth: (x: Comparable<A>) compareTo y")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -18,11 +18,11 @@ fun box(): Boolean {
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!(a equals b)) return false
|
||||
if (a equals c) return false
|
||||
if (Bar() equals Bar()) return false
|
||||
if (!(a.equals(b))) return false
|
||||
if (a.equals(c)) return false
|
||||
if (Bar().equals(Bar())) return false
|
||||
val g = Bar()
|
||||
if (!(g equals g)) return false
|
||||
if (g equals Bar()) return false
|
||||
if (!(g.equals(g))) return false
|
||||
if (g.equals(Bar())) return false
|
||||
return true
|
||||
}
|
||||
+10
-10
@@ -2,20 +2,20 @@ package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = 2
|
||||
if (!(a equals a)) return false
|
||||
if (!(a equals 2)) return false
|
||||
if (!(a equals 2.0)) return false
|
||||
if (!(a.equals(a))) return false
|
||||
if (!(a.equals(2))) return false
|
||||
if (!(a.equals(2.0))) return false
|
||||
val c = "a"
|
||||
if (!("a" equals c)) return false
|
||||
if (!("a".equals(c))) return false
|
||||
if (!((null as Any?)?.equals(null) ?: true)) return false
|
||||
val d = 5.6
|
||||
if (!(d.toShort() equals 5.toShort())) return false
|
||||
if (!(d.toByte() equals 5.toByte())) return false
|
||||
if (!(d.toFloat() equals 5.6.toFloat())) return false
|
||||
if (!(d.toInt() equals 5)) return false
|
||||
if (true equals false) return false
|
||||
if (!(d.toShort().equals(5.toShort()))) return false
|
||||
if (!(d.toByte().equals(5.toByte()))) return false
|
||||
if (!(d.toFloat().equals(5.6.toFloat()))) return false
|
||||
if (!(d.toInt().equals(5))) return false
|
||||
if (true.equals(false)) return false
|
||||
|
||||
val n: Number = 3
|
||||
if (!(n equals 3.3.toInt())) return false
|
||||
if (!(n.equals(3.3.toInt()))) return false
|
||||
return true
|
||||
}
|
||||
+3
-3
@@ -2,12 +2,12 @@ package foo
|
||||
|
||||
class Iter(val upper: Int) {
|
||||
var count: Int = 0
|
||||
fun hasNext(): Boolean = count < upper
|
||||
fun next(): Int = count++
|
||||
operator fun hasNext(): Boolean = count < upper
|
||||
operator fun next(): Int = count++
|
||||
}
|
||||
|
||||
class A(val upper: Int) {
|
||||
fun iterator(): Iter = Iter(upper)
|
||||
operator fun iterator(): Iter = Iter(upper)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
Vendored
+3
-3
@@ -3,18 +3,18 @@ package foo
|
||||
var log = ""
|
||||
|
||||
class T(val id: Int) {
|
||||
fun component1(): Int {
|
||||
operator fun component1(): Int {
|
||||
log += "($id).component1();"
|
||||
return 1
|
||||
}
|
||||
fun component2(): String {
|
||||
operator fun component2(): String {
|
||||
log += "($id).component2();"
|
||||
return "1"
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
fun iterator(): Iterator<T> = object: Iterator<T> {
|
||||
operator fun iterator(): Iterator<T> = object: Iterator<T> {
|
||||
var i = 0
|
||||
var data = arrayOf(T(3), T(1), T(2))
|
||||
override fun hasNext(): Boolean {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// EA-56241
|
||||
package foo
|
||||
|
||||
fun Int.foo(a: Int) = this + a
|
||||
|
||||
val bar = fun Int.(a: Int): Int = this * a
|
||||
|
||||
fun test(op: Int.(Int) -> Int) = 3 op 20
|
||||
|
||||
fun box(): String {
|
||||
val op = fun Int.(a: Int): Int = this / a
|
||||
|
||||
assertEquals(41, 34 foo 7)
|
||||
assertEquals(28, 4 bar 7)
|
||||
assertEquals(-17, test { this - it })
|
||||
assertEquals(7, 49 op 7)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+3
-3
@@ -10,12 +10,12 @@ fun box(): String {
|
||||
val c = a
|
||||
if (!c.identityEquals(a)) return "c = a; c !== a"
|
||||
|
||||
if (X() identityEquals a) return "X() identityEquals a"
|
||||
if (X().identityEquals(a)) return "X() identityEquals a"
|
||||
|
||||
val t = !(X() identityEquals a)
|
||||
val t = !(X().identityEquals(a))
|
||||
if (!t) return "t = !(X() identityEquals a); t == false"
|
||||
|
||||
val f = !!(X() identityEquals a)
|
||||
val f = !!(X().identityEquals(a))
|
||||
if (f) return "f = !!(X() identityEquals null); f == true"
|
||||
return "OK";
|
||||
}
|
||||
Vendored
+5
-5
@@ -2,12 +2,12 @@ package foo
|
||||
|
||||
fun box(): String {
|
||||
if (!null.identityEquals(null)) return "null !== null"
|
||||
if (!("ab" identityEquals "ab")) return "ab !== ab"
|
||||
if (("ab" identityEquals "a")) return "ab === a"
|
||||
if (!("ab".identityEquals("ab"))) return "ab !== ab"
|
||||
if (("ab".identityEquals("a"))) return "ab === a"
|
||||
|
||||
if ("0" identityEquals 0) return "'0' === 0"
|
||||
if (!(0 identityEquals 0)) return "0 !== 0"
|
||||
if (0 identityEquals 1) return "0 === 1"
|
||||
if ("0".identityEquals(0)) return "'0' === 0"
|
||||
if (!(0.identityEquals(0))) return "0 !== 0"
|
||||
if (0.identityEquals(1)) return "0 === 1"
|
||||
|
||||
|
||||
return "OK";
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// KT-3998 Infix call doesn't work for function literals and another classes which implements invoke convention (in JS backend)
|
||||
package foo
|
||||
|
||||
fun test(): String {
|
||||
val a: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = { "a" }
|
||||
val b: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = {
|
||||
val aa = this as @Extension Function2<Any?, Any?, Any?>;
|
||||
val cc = it as @Extension Function2<Any?, Any?, Any?>;
|
||||
"${null.aa(null)} b ${null.cc(null)}"
|
||||
}
|
||||
val c: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = { "c" }
|
||||
|
||||
val f = a.b(c) // works
|
||||
val s = a b c //compiler crashes
|
||||
return "$f | $s"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("a b c | a b c", test())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+4
-4
@@ -10,19 +10,19 @@
|
||||
package foo
|
||||
|
||||
class Bar/* : Function0<String>*/ {
|
||||
fun invoke() = "Bar.invoke()"
|
||||
operator fun invoke() = "Bar.invoke()"
|
||||
}
|
||||
|
||||
class Baz/* : Function2<Int, Boolean, String>*/ {
|
||||
fun invoke(i: Int, b: Boolean) = "Baz.invoke($i, $b)"
|
||||
operator fun invoke(i: Int, b: Boolean) = "Baz.invoke($i, $b)"
|
||||
}
|
||||
|
||||
class Mixed/* :
|
||||
Function1<Int, String>,
|
||||
Function2<Int, Boolean, String>*/
|
||||
{
|
||||
fun invoke(i: Int) = "Mixed.invoke($i)"
|
||||
fun invoke(i: Int, b: Boolean) = "Mixed.invoke($i, $b)"
|
||||
operator fun invoke(i: Int) = "Mixed.invoke($i)"
|
||||
operator fun invoke(i: Int, b: Boolean) = "Mixed.invoke($i, $b)"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
class Foo(val postfix: String) {
|
||||
public fun invoke(text: String): String {
|
||||
operator fun invoke(text: String): String {
|
||||
return text + postfix
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun invoke() = "##"
|
||||
fun invoke(i: Int) = "#${i}"
|
||||
operator fun invoke() = "##"
|
||||
operator fun invoke(i: Int) = "#${i}"
|
||||
}
|
||||
|
||||
fun foo() = A()
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun invoke(i: Int) = i
|
||||
operator fun invoke(i: Int) = i
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun Int.invoke(x: Int) = this + x
|
||||
operator fun Int.invoke(x: Int) = this + x
|
||||
fun box(): Boolean {
|
||||
return 1(2) == 3
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
class Data(val rawData: Array<Int>, val width: Int, val height: Int) {
|
||||
fun get(x: Int, y: Int): ColorLike {
|
||||
operator fun get(x: Int, y: Int): ColorLike {
|
||||
return object : ColorLike {
|
||||
override val red: Int = rawData[(y * width + x) * 4 + 0];
|
||||
override val green: Int = rawData[(y * width + x) * 4 + 1];
|
||||
@@ -9,7 +9,7 @@ class Data(val rawData: Array<Int>, val width: Int, val height: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
fun set(x: Int, y: Int, color: ColorLike) {
|
||||
operator fun set(x: Int, y: Int, color: ColorLike) {
|
||||
rawData[(y * width + x) * 4 + 0] = color.red;
|
||||
rawData[(y * width + x) * 4 + 1] = color.green;
|
||||
rawData[(y * width + x) * 4 + 2] = color.blue;
|
||||
|
||||
@@ -11,7 +11,7 @@ fun box(): Boolean {
|
||||
}
|
||||
|
||||
|
||||
inline public fun myArrayList<T>(vararg values: T): ArrayList<T> {
|
||||
inline public fun <T> myArrayList(vararg values: T): ArrayList<T> {
|
||||
val c = ArrayList<T>()
|
||||
for (v in values) {
|
||||
c.add(v)
|
||||
|
||||
@@ -16,12 +16,12 @@ fun get1(): Int {
|
||||
|
||||
class A() {
|
||||
var p = 0
|
||||
fun get(i: Int): Int {
|
||||
operator fun get(i: Int): Int {
|
||||
c1++
|
||||
return 0
|
||||
}
|
||||
|
||||
fun set(i: Int, value: Int) {
|
||||
operator fun set(i: Int, value: Int) {
|
||||
c2++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ var c2 = 0
|
||||
|
||||
class A() {
|
||||
var p = 0
|
||||
fun divAssign(a: Int) {
|
||||
operator fun divAssign(a: Int) {
|
||||
c1++;
|
||||
}
|
||||
fun times(a: Int): A {
|
||||
operator fun times(a: Int): A {
|
||||
c2++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class RangeIterator(val start: Int, var count: Int, val reversed: Boolean) {
|
||||
|
||||
var i = start
|
||||
|
||||
fun next(): Int {
|
||||
operator fun next(): Int {
|
||||
--count
|
||||
if (reversed) {
|
||||
i--
|
||||
@@ -17,7 +17,7 @@ class RangeIterator(val start: Int, var count: Int, val reversed: Boolean) {
|
||||
}
|
||||
|
||||
|
||||
fun hasNext() = (count > 0);
|
||||
operator fun hasNext() = (count > 0);
|
||||
}
|
||||
|
||||
class NumberRange(val start: Int, val size: Int, val reversed: Boolean) {
|
||||
@@ -34,7 +34,7 @@ class NumberRange(val start: Int, val size: Int, val reversed: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
fun iterator() = RangeIterator(start, size, reversed);
|
||||
operator fun iterator() = RangeIterator(start, size, reversed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -12,12 +12,12 @@ class SimpleEnumerator {
|
||||
}
|
||||
|
||||
class SimpleEnumeratorWrapper(private val enumerator: SimpleEnumerator) {
|
||||
fun hasNext(): Boolean = enumerator.hasMoreElements()
|
||||
operator fun hasNext(): Boolean = enumerator.hasMoreElements()
|
||||
|
||||
fun next() = enumerator.getNext()
|
||||
operator fun next() = enumerator.getNext()
|
||||
}
|
||||
|
||||
fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
|
||||
operator fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
|
||||
return SimpleEnumeratorWrapper(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ fun String.myHashCode(): Int {
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other is Foo) return name == other.name
|
||||
return this identityEquals other
|
||||
return this.identityEquals(other)
|
||||
}
|
||||
override fun hashCode(): Int = name.myHashCode()
|
||||
override fun toString(): String = "Foo($name)"
|
||||
|
||||
@@ -3,11 +3,11 @@ package foo
|
||||
class A
|
||||
|
||||
inline fun compare1(a: A): Boolean {
|
||||
return a identityEquals a
|
||||
return a.identityEquals(a)
|
||||
}
|
||||
|
||||
inline fun compare2(a1: A, a2: A): Boolean {
|
||||
return a1 identityEquals a2
|
||||
return a1.identityEquals(a2)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -5,8 +5,8 @@ package foo
|
||||
|
||||
class A(val a: Int, val b: Int)
|
||||
|
||||
inline fun A.component1(): Int = a
|
||||
inline fun A.component2(): Int = b
|
||||
inline operator fun A.component1(): Int = a
|
||||
inline operator fun A.component2(): Int = b
|
||||
|
||||
fun box(): String {
|
||||
val (a, b) = A(1, 2)
|
||||
|
||||
@@ -4,10 +4,9 @@ package foo
|
||||
|
||||
class A(val x: Int, val y: Int)
|
||||
|
||||
fun A.component1(): Int = fizz(x)
|
||||
operator fun A.component1(): Int = fizz(x)
|
||||
|
||||
inline
|
||||
fun A.component2(): Int = buzz(y)
|
||||
inline operator fun A.component2(): Int = buzz(y)
|
||||
|
||||
fun box(): String {
|
||||
val (a, b) = A(1, 2)
|
||||
|
||||
+5
-8
@@ -6,18 +6,15 @@ package foo
|
||||
|
||||
class A(val a: Int, val b: Int, val c: Int, val d: Int, val e: Int)
|
||||
|
||||
fun A.component1(): Int = fizz(a)
|
||||
operator fun A.component1(): Int = fizz(a)
|
||||
|
||||
inline
|
||||
fun A.component2(): Int = buzz(b)
|
||||
inline operator fun A.component2(): Int = buzz(b)
|
||||
|
||||
inline
|
||||
fun A.component3(): Int = buzz(c)
|
||||
inline operator fun A.component3(): Int = buzz(c)
|
||||
|
||||
fun A.component4(): Int = fizz(d)
|
||||
operator fun A.component4(): Int = fizz(d)
|
||||
|
||||
inline
|
||||
fun A.component5(): Int = buzz(e)
|
||||
inline operator fun A.component5(): Int = buzz(e)
|
||||
|
||||
fun box(): String {
|
||||
val (a, b, c, d, e) = A(1, 2, 3, 4, 5)
|
||||
|
||||
@@ -28,7 +28,7 @@ abstract class Tag(val name: String) : Element() {
|
||||
val children = ArrayList<Element>()
|
||||
val attributes = HashMap<String, String>()
|
||||
|
||||
inline protected fun initTag<T : Element>(tag: T, init: T.() -> Unit): T {
|
||||
inline protected fun <T : Element> initTag(tag: T, init: T.() -> Unit): T {
|
||||
tag.init()
|
||||
children.add(tag)
|
||||
return tag
|
||||
@@ -52,7 +52,7 @@ abstract class Tag(val name: String) : Element() {
|
||||
}
|
||||
|
||||
abstract class TagWithText(name: String) : Tag(name) {
|
||||
fun String.plus() {
|
||||
operator fun String.unaryPlus() {
|
||||
children.add(TextElement(this))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ abstract class Tag(val name: String) : Element() {
|
||||
val children = ArrayList<Element>()
|
||||
val attributes = HashMap<String, String>()
|
||||
|
||||
inline protected fun initTag<T : Element>(tag: T, init: T.() -> Unit): T {
|
||||
inline protected fun <T : Element> initTag(tag: T, init: T.() -> Unit): T {
|
||||
tag.init()
|
||||
children.add(tag)
|
||||
return tag
|
||||
@@ -52,7 +52,7 @@ abstract class Tag(val name: String) : Element() {
|
||||
}
|
||||
|
||||
abstract class TagWithText(name: String) : Tag(name) {
|
||||
fun String.plus() {
|
||||
operator fun String.unaryPlus() {
|
||||
children.add(TextElement(this))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ public fun Input.copyTo(output: Output, size: Int): Int {
|
||||
return output.doOutput(this.data())
|
||||
}
|
||||
|
||||
public inline fun with2<T>(receiver : T, crossinline body : T.() -> Unit) : Unit = {receiver.body()}()
|
||||
public inline fun <T> with2(receiver : T, crossinline body : T.() -> Unit) : Unit = {receiver.body()}()
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, fn: (T)->R): R =
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, fn: T.()->R): R =
|
||||
public fun <T, R> apply(x: T, fn: T.()->R): R =
|
||||
x.fn()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, fn: (T)->R): R =
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, crossinline fn: (T)->R): R {
|
||||
public fun <T, R> apply(x: T, crossinline fn: (T)->R): R {
|
||||
val result = object {
|
||||
val x = fn(x)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, fn: (T)->R): R =
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun apply<T, R>(x: T, fn: (T)->R): R {
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R {
|
||||
val y = fn(x)
|
||||
return y
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ package foo
|
||||
// A copy of stdlib run function.
|
||||
// Copied to not to depend on run implementation.
|
||||
// It's important, that the body is just `return fn()`.
|
||||
internal inline fun evaluate<T>(fn: ()->T): T = fn()
|
||||
internal inline fun <T> evaluate(fn: ()->T): T = fn()
|
||||
|
||||
internal fun test(x: Int): Int =
|
||||
evaluate {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun component1(): Int = 1
|
||||
operator fun component1(): Int = 1
|
||||
}
|
||||
fun A.component2(): String = "n"
|
||||
operator fun A.component2(): String = "n"
|
||||
|
||||
fun box(): String {
|
||||
val list = Array<A>(1, { A() })
|
||||
|
||||
@@ -3,18 +3,18 @@ package foo
|
||||
import java.util.HashMap
|
||||
|
||||
|
||||
public fun <K, V> Map<K, V>.iterator(): Iterator<Map.Entry<K, V>> {
|
||||
operator fun <K, V> Map<K, V>.iterator(): Iterator<Map.Entry<K, V>> {
|
||||
val entrySet = this.entrySet()
|
||||
return entrySet.iterator()
|
||||
}
|
||||
|
||||
/** Returns the key of the entry */
|
||||
fun <K, V> Map.Entry<K, V>.component1(): K {
|
||||
operator fun <K, V> Map.Entry<K, V>.component1(): K {
|
||||
return getKey()
|
||||
}
|
||||
|
||||
/** Returns the value of the entry */
|
||||
fun <K, V> Map.Entry<K, V>.component2(): V {
|
||||
operator fun <K, V> Map.Entry<K, V>.component2(): V {
|
||||
return getValue()
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ fun ComparableRange<C>.iterator(): Iterator<C> {
|
||||
}
|
||||
|
||||
open class A {
|
||||
fun component1(): Int = 1
|
||||
operator fun component1(): Int = 1
|
||||
}
|
||||
fun A.component2(): String = "n"
|
||||
operator fun A.component2(): String = "n"
|
||||
|
||||
fun box(): String {
|
||||
var i = 0;
|
||||
|
||||
@@ -3,9 +3,9 @@ package foo
|
||||
import java.util.ArrayList
|
||||
|
||||
class A {
|
||||
fun component1(): Int = 1
|
||||
operator fun component1(): Int = 1
|
||||
}
|
||||
fun A.component2(): String = "n"
|
||||
operator fun A.component2(): String = "n"
|
||||
|
||||
fun box(): String {
|
||||
val list = ArrayList<A>()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun Int.component1(): Int {
|
||||
operator fun Int.component1(): Int {
|
||||
return this + 10;
|
||||
}
|
||||
|
||||
fun Int.component2(): String = "b"
|
||||
operator fun Int.component2(): String = "b"
|
||||
|
||||
fun box(): String {
|
||||
var i = 0;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun Int.component1(): Int {
|
||||
operator fun Int.component1(): Int {
|
||||
return this + 10;
|
||||
}
|
||||
|
||||
fun Int.component2(): String = "b"
|
||||
operator fun Int.component2(): String = "b"
|
||||
|
||||
fun box(): String {
|
||||
var i = 0;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun component1(): Int = 1
|
||||
operator fun component1(): Int = 1
|
||||
}
|
||||
fun A.component2(): String = "n"
|
||||
operator fun A.component2(): String = "n"
|
||||
|
||||
class B {
|
||||
fun component1(): Int = 1
|
||||
fun component2(): Int = 2
|
||||
fun component3(): Int = 3
|
||||
operator fun component1(): Int = 1
|
||||
operator fun component2(): Int = 2
|
||||
operator fun component3(): Int = 3
|
||||
}
|
||||
|
||||
class C {
|
||||
fun component1(): Int = 42
|
||||
operator fun component1(): Int = 42
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
+2
-2
@@ -8,6 +8,6 @@ val classes: Map<String, Any> = noImpl
|
||||
val classesMutable: HashMap<String, String> = noImpl
|
||||
|
||||
fun box(): Boolean {
|
||||
classesMutable["why"] = "?"
|
||||
return classes["answer"] == 42 && classesMutable["why"] == "?"
|
||||
classesMutable.set("why", "?")
|
||||
return classes.get("answer") == 42 && classesMutable.get("why") == "?"
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package foo
|
||||
@native("Object")
|
||||
class JsObject {
|
||||
@nativeGetter
|
||||
fun get(a: String): Any? = noImpl
|
||||
operator fun get(a: String): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
fun set(a: String, v: Any?): Unit = noImpl
|
||||
operator fun set(a: String, v: Any?): Unit = noImpl
|
||||
|
||||
@nativeGetter
|
||||
fun take(a: Int): Any? = noImpl
|
||||
@@ -16,10 +16,10 @@ class JsObject {
|
||||
}
|
||||
|
||||
@nativeGetter
|
||||
fun JsObject.get(a: Int): Any? = noImpl
|
||||
operator fun JsObject.get(a: Int): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
fun JsObject.set(a: Int, v: Any?): Unit = noImpl
|
||||
operator fun JsObject.set(a: Int, v: Any?): Unit = noImpl
|
||||
|
||||
@nativeGetter
|
||||
fun JsObject.take(a: String): Any? = noImpl
|
||||
|
||||
+2
-2
@@ -3,14 +3,14 @@ package foo
|
||||
@native
|
||||
class Function(vararg argsAndCode: String) {
|
||||
@nativeInvoke
|
||||
fun invoke(a: Any?): Any? = noImpl
|
||||
operator fun invoke(a: Any?): Any? = noImpl
|
||||
|
||||
@nativeInvoke
|
||||
fun baz(a: Any?, b: Any?): Any? = noImpl
|
||||
}
|
||||
|
||||
@nativeInvoke
|
||||
fun Function.invoke(a: Any?, b: Any?): Any? = noImpl
|
||||
operator fun Function.invoke(a: Any?, b: Any?): Any? = noImpl
|
||||
|
||||
@nativeInvoke
|
||||
fun Function.bar(a: Any?, b: Any?): Any? = noImpl
|
||||
|
||||
+93
-93
@@ -12,113 +12,113 @@ fun box(): String {
|
||||
assertEquals(-1, 1.compareTo(2))
|
||||
assertEquals(-1, (1 as Comparable<Int>).compareTo(2))
|
||||
|
||||
assertEquals(-1, 1 compareTo 2L)
|
||||
assertEquals(-1, 1 compareTo 2L)
|
||||
assertEquals(-1, 1 compareTo 7540113804746346429L)
|
||||
assertEquals(-1, 1 compareTo 2.toShort())
|
||||
assertEquals(-1, 1 compareTo 2.toByte())
|
||||
assertEquals(-1, 1 compareTo 2.0)
|
||||
assertEquals(-1, 1 compareTo 2.0f)
|
||||
assertEquals(-1, 1.compareTo(2L))
|
||||
assertEquals(-1, 1.compareTo(2L))
|
||||
assertEquals(-1, 1.compareTo(7540113804746346429L))
|
||||
assertEquals(-1, 1.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1.compareTo(2.0))
|
||||
assertEquals(-1, 1.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10 compareTo 2L)
|
||||
assertEquals(1, 10 compareTo 2)
|
||||
assertEquals(1, 10 compareTo 2.toShort())
|
||||
assertEquals(1, 10 compareTo 2.toByte())
|
||||
assertEquals(1, 10 compareTo 2.0)
|
||||
assertEquals(1, 10 compareTo 2.0f)
|
||||
assertEquals(1, 10.compareTo(2L))
|
||||
assertEquals(1, 10.compareTo(2))
|
||||
assertEquals(1, 10.compareTo(2.toShort()))
|
||||
assertEquals(1, 10.compareTo(2.toByte()))
|
||||
assertEquals(1, 10.compareTo(2.0))
|
||||
assertEquals(1, 10.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2 compareTo 2L)
|
||||
assertEquals(0, 2 compareTo 2)
|
||||
assertEquals(0, 2 compareTo 2.toShort())
|
||||
assertEquals(0, 2 compareTo 2.toByte())
|
||||
assertEquals(0, 2 compareTo 2.0)
|
||||
assertEquals(0, 2 compareTo 2.0f)
|
||||
assertEquals(0, 2.compareTo(2L))
|
||||
assertEquals(0, 2.compareTo(2))
|
||||
assertEquals(0, 2.compareTo(2.toShort()))
|
||||
assertEquals(0, 2.compareTo(2.toByte()))
|
||||
assertEquals(0, 2.compareTo(2.0))
|
||||
assertEquals(0, 2.compareTo(2.0f))
|
||||
|
||||
assertEquals(-1, 1.toShort() compareTo 2L)
|
||||
assertEquals(-1, 1.toShort() compareTo 7540113804746346429L)
|
||||
assertEquals(-1, 1.toShort() compareTo 2)
|
||||
assertEquals(-1, 1.toShort() compareTo 2.toShort())
|
||||
assertEquals(-1, (1.toShort() as Comparable<Short>) compareTo 2.toShort())
|
||||
assertEquals(-1, 1.toShort() compareTo 2.toByte())
|
||||
assertEquals(-1, 1.toShort() compareTo 2.0)
|
||||
assertEquals(-1, 1.toShort() compareTo 2.0f)
|
||||
assertEquals(-1, 1.toShort().compareTo(2L))
|
||||
assertEquals(-1, 1.toShort().compareTo(7540113804746346429L))
|
||||
assertEquals(-1, 1.toShort().compareTo(2))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.toShort()))
|
||||
assertEquals(-1, (1.toShort() as Comparable<Short>).compareTo(2.toShort()))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.toByte()))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.0))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10.toByte() compareTo 2L)
|
||||
assertEquals(-1, 10.toByte() compareTo 7540113804746346429L)
|
||||
assertEquals(1, 10.toByte() compareTo 2)
|
||||
assertEquals(1, 10.toByte() compareTo 2.toShort())
|
||||
assertEquals(1, 10.toByte() compareTo 2.toByte())
|
||||
assertEquals(1, (10.toByte() as Comparable<Byte>) compareTo 2.toByte())
|
||||
assertEquals(1, 10.toByte() compareTo 2.0)
|
||||
assertEquals(1, 10.toByte() compareTo 2.0f)
|
||||
assertEquals(1, 10.toByte().compareTo(2L))
|
||||
assertEquals(-1, 10.toByte().compareTo(7540113804746346429L))
|
||||
assertEquals(1, 10.toByte().compareTo(2))
|
||||
assertEquals(1, 10.toByte().compareTo(2.toShort()))
|
||||
assertEquals(1, 10.toByte().compareTo(2.toByte()))
|
||||
assertEquals(1, (10.toByte() as Comparable<Byte>).compareTo(2.toByte()))
|
||||
assertEquals(1, 10.toByte().compareTo(2.0))
|
||||
assertEquals(1, 10.toByte().compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2.0 compareTo 2L)
|
||||
assertEquals(-1, 2.0 compareTo 7540113804746346429L)
|
||||
assertEquals(0, 2.0 compareTo 2)
|
||||
assertEquals(0, 2.0 compareTo 2.toShort())
|
||||
assertEquals(0, 2.0 compareTo 2.toByte())
|
||||
assertEquals(0, 2.0 compareTo 2.0)
|
||||
assertEquals(0, (2.0 as Comparable<Double>) compareTo 2.0)
|
||||
assertEquals(0, 2.0 compareTo 2.0f)
|
||||
assertEquals(0, 2.0.compareTo(2L))
|
||||
assertEquals(-1, 2.0.compareTo(7540113804746346429L))
|
||||
assertEquals(0, 2.0.compareTo(2))
|
||||
assertEquals(0, 2.0.compareTo(2.toShort()))
|
||||
assertEquals(0, 2.0.compareTo(2.toByte()))
|
||||
assertEquals(0, 2.0.compareTo(2.0))
|
||||
assertEquals(0, (2.0 as Comparable<Double>).compareTo(2.0))
|
||||
assertEquals(0, 2.0.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 3.0f compareTo 2L)
|
||||
assertEquals(-1, 3.0f compareTo 7540113804746346429L)
|
||||
assertEquals(1, 3.0f compareTo 2)
|
||||
assertEquals(1, 3.0f compareTo 2.toShort())
|
||||
assertEquals(1, 3.0f compareTo 2.toByte())
|
||||
assertEquals(1, 3.0f compareTo 2.0)
|
||||
assertEquals(1, 3.0f compareTo 2.0f)
|
||||
assertEquals(1, (3.0f as Comparable<Float>) compareTo 2.0f)
|
||||
assertEquals(1, 3.0f.compareTo(2L))
|
||||
assertEquals(-1, 3.0f.compareTo(7540113804746346429L))
|
||||
assertEquals(1, 3.0f.compareTo(2))
|
||||
assertEquals(1, 3.0f.compareTo(2.toShort()))
|
||||
assertEquals(1, 3.0f.compareTo(2.toByte()))
|
||||
assertEquals(1, 3.0f.compareTo(2.0))
|
||||
assertEquals(1, 3.0f.compareTo(2.0f))
|
||||
assertEquals(1, (3.0f as Comparable<Float>).compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10L compareTo 2L)
|
||||
assertEquals(-1, 10L compareTo 7540113804746346429L)
|
||||
assertEquals(1, (10L as Comparable<Long>) compareTo 2L)
|
||||
assertEquals(1, 10L compareTo 2)
|
||||
assertEquals(1, 10L compareTo 2.toShort())
|
||||
assertEquals(1, 10L compareTo 2.toByte())
|
||||
assertEquals(1, 10L compareTo 2.0)
|
||||
assertEquals(1, 10L compareTo 2.0f)
|
||||
assertEquals(1, 10L.compareTo(2L))
|
||||
assertEquals(-1, 10L.compareTo(7540113804746346429L))
|
||||
assertEquals(1, (10L as Comparable<Long>).compareTo(2L))
|
||||
assertEquals(1, 10L.compareTo(2))
|
||||
assertEquals(1, 10L.compareTo(2.toShort()))
|
||||
assertEquals(1, 10L.compareTo(2.toByte()))
|
||||
assertEquals(1, 10L.compareTo(2.0))
|
||||
assertEquals(1, 10L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 'A' compareTo 'A')
|
||||
assertEquals(0, 'A'.compareTo('A'))
|
||||
|
||||
assertEquals(-1, 1L compareTo 2L)
|
||||
assertEquals(-1, 1L compareTo 2)
|
||||
assertEquals(-1, 1L compareTo 2.toShort())
|
||||
assertEquals(-1, 1L compareTo 2.toByte())
|
||||
assertEquals(-1, 1L compareTo 2.0)
|
||||
assertEquals(-1, 1L compareTo 2.0f)
|
||||
assertEquals(-1, 1L.compareTo(2L))
|
||||
assertEquals(-1, 1L.compareTo(2))
|
||||
assertEquals(-1, 1L.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1L.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1L.compareTo(2.0))
|
||||
assertEquals(-1, 1L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 7540113804746346429L compareTo 7540113804746346429L)
|
||||
assertEquals(1, 7540113804746346429L compareTo 2L)
|
||||
assertEquals(0, 2L compareTo 2L)
|
||||
assertEquals(0, 2L compareTo 2)
|
||||
assertEquals(0, 2L compareTo 2.toShort())
|
||||
assertEquals(0, 2L compareTo 2.toByte())
|
||||
assertEquals(0, 2L compareTo 2.0)
|
||||
assertEquals(0, 2L compareTo 2.0f)
|
||||
assertEquals(0, 7540113804746346429L.compareTo(7540113804746346429L))
|
||||
assertEquals(1, 7540113804746346429L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2))
|
||||
assertEquals(0, 2L.compareTo(2.toShort()))
|
||||
assertEquals(0, 2L.compareTo(2.toByte()))
|
||||
assertEquals(0, 2L.compareTo(2.0))
|
||||
assertEquals(0, 2L.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10L compareTo 2L)
|
||||
assertEquals(1, 10L compareTo 2)
|
||||
assertEquals(1, 10L compareTo 2.toShort())
|
||||
assertEquals(1, 10L compareTo 2.toByte())
|
||||
assertEquals(1, 10L compareTo 2.0)
|
||||
assertEquals(1, 10L compareTo 2.0f)
|
||||
assertEquals(1, 10L.compareTo(2L))
|
||||
assertEquals(1, 10L.compareTo(2))
|
||||
assertEquals(1, 10L.compareTo(2.toShort()))
|
||||
assertEquals(1, 10L.compareTo(2.toByte()))
|
||||
assertEquals(1, 10L.compareTo(2.0))
|
||||
assertEquals(1, 10L.compareTo(2.0f))
|
||||
|
||||
assertEquals(-1, 1L compareTo 2L)
|
||||
assertEquals(-1, 1L compareTo 2)
|
||||
assertEquals(-1, 1L compareTo 2.toShort())
|
||||
assertEquals(-1, 1L compareTo 2.toByte())
|
||||
assertEquals(-1, 1L compareTo 2.0)
|
||||
assertEquals(-1, 1L compareTo 2.0f)
|
||||
assertEquals(-1, 1L.compareTo(2L))
|
||||
assertEquals(-1, 1L.compareTo(2))
|
||||
assertEquals(-1, 1L.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1L.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1L.compareTo(2.0))
|
||||
assertEquals(-1, 1L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2L compareTo 2L)
|
||||
assertEquals(0, 2L compareTo 2)
|
||||
assertEquals(0, 2L compareTo 2.toShort())
|
||||
assertEquals(0, 2L compareTo 2.toByte())
|
||||
assertEquals(0, 2L compareTo 2.0)
|
||||
assertEquals(0, 2L compareTo 2.0f)
|
||||
assertEquals(0, 2L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2))
|
||||
assertEquals(0, 2L.compareTo(2.toShort()))
|
||||
assertEquals(0, 2L.compareTo(2.toByte()))
|
||||
assertEquals(0, 2L.compareTo(2.0))
|
||||
assertEquals(0, 2L.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, id("A", 10) compareTo id("B", 5))
|
||||
assertEquals(1, id("A", 10).compareTo(id("B", 5)))
|
||||
assertEquals("AB", global)
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A() {
|
||||
|
||||
fun div(other: A) = "hooray"
|
||||
operator fun div(other: A) = "hooray"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
|
||||
class A(t: Int) {
|
||||
var i = t
|
||||
fun compareTo(other: A) = (this.i - other.i)
|
||||
operator fun compareTo(other: A) = (this.i - other.i)
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
|
||||
class A(t: Int) {
|
||||
var i = t
|
||||
fun compareTo(other: A) = (this.i - other.i)
|
||||
infix operator fun compareTo(other: A) = (this.i - other.i)
|
||||
}
|
||||
|
||||
fun box(): Boolean =
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A() {
|
||||
|
||||
fun not() = "hooray"
|
||||
operator fun not() = "hooray"
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class MyInt(i: Int) {
|
||||
var b = i
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
b = b + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ class ArrayWrapper<T>() {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
operator fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
contents.addAll(rhs.contents)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ class A<T>(val list: MutableList<T>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> A<T>.plusAssign(other: Collection<T>) {
|
||||
operator fun <T> A<T>.plusAssign(other: Collection<T>) {
|
||||
addAll(other)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -3,10 +3,10 @@ package foo
|
||||
open class Foo<out T>(open val value: T)
|
||||
open class MutableFoo<T>(override var value: T): Foo<T>(value)
|
||||
|
||||
fun <T> Foo<T>.plus(x: T): Foo<T> = Foo(x)
|
||||
operator fun <T> Foo<T>.plus(x: T): Foo<T> = Foo(x)
|
||||
|
||||
// overloading:
|
||||
fun <T> MutableFoo<T>.plus(x: T): MutableFoo<T> = MutableFoo(x)
|
||||
operator fun <T> MutableFoo<T>.plus(x: T): MutableFoo<T> = MutableFoo(x)
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun <T> ArrayList<T>.plus(other: Collection<T>): List<T> {
|
||||
operator fun <T> ArrayList<T>.plus(other: Collection<T>): List<T> {
|
||||
val c = ArrayList<T>()
|
||||
c.addAll(this)
|
||||
c.addAll(other)
|
||||
|
||||
Vendored
+2
-2
@@ -4,8 +4,8 @@ class A(val c: Int) {
|
||||
}
|
||||
|
||||
|
||||
fun A.inc() = A(5)
|
||||
fun A.dec() = A(10)
|
||||
operator fun A.inc() = A(5)
|
||||
operator fun A.dec() = A(10)
|
||||
|
||||
fun box(): Boolean {
|
||||
var a = A(1)
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ var a = MyInt()
|
||||
class MyInt() {
|
||||
var b = 0
|
||||
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
val res = MyInt();
|
||||
res.b = b;
|
||||
res.b++;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ package foo
|
||||
|
||||
class A() {
|
||||
|
||||
fun plus() = "hooray"
|
||||
fun minus() = "not really"
|
||||
operator fun unaryPlus() = "hooray"
|
||||
operator fun unaryMinus() = "not really"
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package foo
|
||||
class A() {
|
||||
|
||||
var message = ""
|
||||
fun plusAssign(other: A) {
|
||||
operator fun plusAssign(other: A) {
|
||||
message = message + "!"
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
class myInt(a: Int) {
|
||||
val value = a;
|
||||
|
||||
fun plus(other: myInt): myInt = myInt(value + other.value)
|
||||
operator fun plus(other: myInt): myInt = myInt(value + other.value)
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
class MyInt() {
|
||||
var b = 0
|
||||
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
val res = MyInt()
|
||||
res.b++;
|
||||
return res;
|
||||
|
||||
@@ -5,7 +5,7 @@ var a = MyInt()
|
||||
class MyInt() {
|
||||
var b = 0
|
||||
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
b = b + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
class MyInt() {
|
||||
var b = 0
|
||||
|
||||
fun dec(): MyInt {
|
||||
operator fun dec(): MyInt {
|
||||
val res = MyInt()
|
||||
res.b++;
|
||||
return res;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package foo
|
||||
class MyInt() {
|
||||
var b = 0
|
||||
|
||||
fun dec(): MyInt {
|
||||
operator fun dec(): MyInt {
|
||||
b = b + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class MyInt(i: Int) {
|
||||
var b = i
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
b = b++;
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class MyInt(i: Int) {
|
||||
var b = i
|
||||
fun inc(): MyInt {
|
||||
operator fun inc(): MyInt {
|
||||
b++;
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A() {
|
||||
var p = "yeah"
|
||||
fun mod(other: A): A {
|
||||
operator fun mod(other: A): A {
|
||||
return A();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import java.util.ArrayList
|
||||
|
||||
fun box(): Boolean {
|
||||
var elems = ArrayList<Int>()
|
||||
for (i in 0 rangeTo 5) {
|
||||
for (i in 0.rangeTo(5)) {
|
||||
elems.add(i)
|
||||
}
|
||||
return elems[0] == 0 && elems[1] == 1 && elems[2] == 2 && elems[3] == 3 && elems[4] == 4 && elems[5] == 5
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
import java.util.ArrayList
|
||||
|
||||
fun box(): Boolean {
|
||||
for (i in 0 rangeTo -1) {
|
||||
for (i in 0.rangeTo(-1)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package foo
|
||||
|
||||
inline fun isInstance<reified T>(x: Any): Boolean =
|
||||
inline fun <reified T> isInstance(x: Any): Boolean =
|
||||
x is T
|
||||
@@ -38,7 +38,7 @@ fun A.extFun(): Int {
|
||||
}
|
||||
|
||||
class B {
|
||||
fun invoke(): Int {
|
||||
operator fun invoke(): Int {
|
||||
c5++
|
||||
return 2
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Image(val src: String, override var pos: Vector, var imageSize: Vector) :
|
||||
imageSize.x, imageSize.y)
|
||||
}
|
||||
|
||||
fun contains(mousePos: Vector): Boolean = mousePos.isInRect(pos, imageSize)
|
||||
operator fun contains(mousePos: Vector): Boolean = mousePos.isInRect(pos, imageSize)
|
||||
}
|
||||
|
||||
class Button(val src: String, override var pos: Vector, var imageSize: Vector) : Shape() {
|
||||
@@ -121,7 +121,7 @@ class Button(val src: String, override var pos: Vector, var imageSize: Vector) :
|
||||
}
|
||||
|
||||
|
||||
fun contains(mousePos: Vector): Boolean = mousePos.isInRect(pos, imageSize)
|
||||
operator fun contains(mousePos: Vector): Boolean = mousePos.isInRect(pos, imageSize)
|
||||
}
|
||||
|
||||
class Border() : Shape() {
|
||||
@@ -484,9 +484,9 @@ abstract class Shape() {
|
||||
|
||||
class Vector(val x: Double = 0.0, val y: Double = 0.0) {
|
||||
operator fun plus(v: Vector) = v(x + v.x, y + v.y)
|
||||
operator fun minus() = v(-x, -y)
|
||||
operator fun unaryMinus() = v(-x, -y)
|
||||
operator fun minus(v: Vector) = v(x - v.x, y - v.y)
|
||||
fun times(koef: Double) = v(x * koef, y * koef)
|
||||
operator fun times(koef: Double) = v(x * koef, y * koef)
|
||||
fun distanceTo(v: Vector) = Math.sqrt((this - v).sqr)
|
||||
fun rotatedBy(theta: Double): Vector {
|
||||
val sin = Math.sin(theta)
|
||||
|
||||
@@ -36,7 +36,7 @@ class Field(
|
||||
liveCount(i + 1, j + 1)
|
||||
|
||||
// You can say field[i, j], and this function gets called
|
||||
fun get(i: Int, j: Int) = live[i][j]
|
||||
operator fun get(i: Int, j: Int) = live[i][j]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user