Fix tests: "infix modifier required" and "operator modifier required" errors
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun box(): String {
|
||||
return justPrint(9 compareTo 4)
|
||||
return justPrint(9.compareTo(4))
|
||||
}
|
||||
|
||||
fun justPrint(value: Int): String {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun Int.test(x : Int) : Int {
|
||||
infix fun Int.test(x : Int) : Int {
|
||||
if (this > 1) {
|
||||
return (this - 1) test x
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class A
|
||||
|
||||
class B {
|
||||
fun A.invoke() = "##"
|
||||
fun A.invoke(i: Int) = "#${i}"
|
||||
operator fun A.invoke() = "##"
|
||||
operator fun A.invoke(i: Int) = "#${i}"
|
||||
}
|
||||
|
||||
fun foo() = A()
|
||||
|
||||
@@ -5,7 +5,7 @@ fun test1(predicate: (Int) -> Int, i: Int) = predicate(i)
|
||||
fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i)
|
||||
|
||||
class Method {
|
||||
fun invoke(i: Int) = i
|
||||
operator fun invoke(i: Int) = i
|
||||
}
|
||||
|
||||
fun test3(method: Method, i: Int) = method.invoke(i)
|
||||
@@ -14,7 +14,7 @@ fun test4(method: Method, i: Int) = method(i)
|
||||
|
||||
class Method2 {}
|
||||
|
||||
fun Method2.invoke(s: String) = s
|
||||
operator fun Method2.invoke(s: String) = s
|
||||
|
||||
fun test5(method2: Method2, s: String) = method2(s)
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
//KT-2728 Can't compile A()()
|
||||
|
||||
class A {
|
||||
fun invoke() = "##"
|
||||
fun invoke(i: Int) = "#${i}"
|
||||
operator fun invoke() = "##"
|
||||
operator fun invoke(i: Int) = "#${i}"
|
||||
}
|
||||
|
||||
fun foo() = A()
|
||||
|
||||
@@ -11,5 +11,5 @@ class Bad(val a: () -> Int) {
|
||||
|
||||
fun test(): Int = a()
|
||||
|
||||
fun invoke(): Int = 2
|
||||
operator fun invoke(): Int = 2
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//KT-3297 Calling the wrong function inside an extension method to the Function0 class
|
||||
|
||||
fun <R> Function0<R>.or(alt: () -> R): R {
|
||||
infix fun <R> Function0<R>.or(alt: () -> R): R {
|
||||
try {
|
||||
return this()
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
public class A(val s: String) {
|
||||
|
||||
public fun get(i: Int) : A = A("$s + $i")
|
||||
operator fun get(i: Int) : A = A("$s + $i")
|
||||
|
||||
public fun invoke(builder : A.() -> String): String = builder()
|
||||
operator fun invoke(builder : A.() -> String): String = builder()
|
||||
}
|
||||
fun x(y : String) : A = A(y)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//KT-3631 String.invoke doesn't work with literals
|
||||
|
||||
fun String.invoke(i: Int) = "$this$i"
|
||||
operator fun String.invoke(i: Int) = "$this$i"
|
||||
|
||||
fun box() = if ("a"(12) == "a12") "OK" else "fail"
|
||||
@@ -5,7 +5,7 @@ open class A {
|
||||
}
|
||||
|
||||
class B {
|
||||
fun invoke(f: B.() -> Unit) = 2
|
||||
operator fun invoke(f: B.() -> Unit) = 2
|
||||
}
|
||||
|
||||
open class C
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//KT-3821 Invoke convention doesn't work for `this`
|
||||
|
||||
class A() {
|
||||
fun invoke() = 42
|
||||
operator fun invoke() = 42
|
||||
fun foo() = this() // Expecting a function type, but found A
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ public fun<TItem> Iterable<TItem>.lazy() : Iterable<TItem>
|
||||
}
|
||||
}
|
||||
|
||||
fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
|
||||
infix fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
|
||||
{
|
||||
return YieldingIterable {
|
||||
val iterator = this.iterator()
|
||||
@@ -45,7 +45,7 @@ fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
|
||||
}
|
||||
}
|
||||
|
||||
fun<TItem, TResult> Iterable<TItem>.select(selector : (TItem)->TResult) : Iterable<TResult>
|
||||
infix fun<TItem, TResult> Iterable<TItem>.select(selector : (TItem)->TResult) : Iterable<TResult>
|
||||
{
|
||||
return YieldingIterable {
|
||||
val iterator = this.iterator();
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
|
||||
interface MyIterator<T> {
|
||||
fun hasNext() : Boolean
|
||||
fun next() : T
|
||||
operator fun hasNext() : Boolean
|
||||
operator fun next() : T
|
||||
}
|
||||
|
||||
fun <T : Any> T?.iterator() = object : MyIterator<T> {
|
||||
operator fun <T : Any> T?.iterator() = object : MyIterator<T> {
|
||||
var hasNext = this@iterator != null
|
||||
private set
|
||||
override fun hasNext() = hasNext
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun foo(): Int {
|
||||
val a = "test"
|
||||
val b = "test"
|
||||
return a compareTo b
|
||||
return a.compareTo(b)
|
||||
}
|
||||
|
||||
fun box(): String = if(foo() == 0) "OK" else "Fail"
|
||||
|
||||
+3
-3
@@ -7,15 +7,15 @@ class B {
|
||||
}
|
||||
|
||||
fun test1(a: A): Int {
|
||||
return a[1]
|
||||
return a.get(1)
|
||||
}
|
||||
|
||||
fun test2(a: A): Int {
|
||||
return a[1, 2]
|
||||
return a.get(1, 2)
|
||||
}
|
||||
|
||||
fun test3(b: B): Int {
|
||||
return b[Unit, Unit]
|
||||
return b.get(Unit, Unit)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ fun foo(f: (Int?) -> Int): Int {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
fun Int?.plus(a:Int) : Int = a!! + 2
|
||||
infix operator fun Int?.plus(a: Int) : Int = a!! + 2
|
||||
|
||||
if (foo { it + 1} != 3) return "Fail 1"
|
||||
if (foo { it plus 1} != 3) return "Fail 2"
|
||||
if (foo { it + 1 } != 3) return "Fail 1"
|
||||
if (foo { it plus 1 } != 3) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box(): String {
|
||||
fun Int.foo(a: Int): Int = a + 2
|
||||
infix fun Int.foo(a: Int): Int = a + 2
|
||||
|
||||
val s = object {
|
||||
fun test(): Int {
|
||||
|
||||
@@ -3,7 +3,7 @@ class T(val value: Int) {
|
||||
|
||||
fun local() : Int {
|
||||
|
||||
fun T.get(s: Int): Int {
|
||||
operator fun T.get(s: Int): Int {
|
||||
return s * this.value
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
open class T(var value: Int) {}
|
||||
|
||||
fun plusAssign(): T {
|
||||
operator fun plusAssign(): T {
|
||||
|
||||
fun T.plusAssign(s: Int) {
|
||||
operator fun T.plusAssign(s: Int) {
|
||||
value += s
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ fun box(): String {
|
||||
|
||||
|
||||
fun selectMetaRunnerId(): String {
|
||||
fun Int?.inc() = (this ?: 0) + 1
|
||||
operator fun Int?.inc() = (this ?: 0) + 1
|
||||
var counter: Int? = null
|
||||
fun path(metaRunnerId: String) = counter != 2
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Z {}
|
||||
|
||||
fun box(): String {
|
||||
fun Z.plus(s : String, d : String = "K") : String {
|
||||
operator fun Z.plus(s : String, d : String = "K") : String {
|
||||
return s + d
|
||||
}
|
||||
return Z() + "O"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun String.plus() : String {
|
||||
operator fun String.unaryPlus() : String {
|
||||
if (this == "") {
|
||||
return "done"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class C
|
||||
|
||||
fun C.compareTo(o: C) : Int {
|
||||
operator fun C.compareTo(o: C) : Int {
|
||||
if (this == o) return 0
|
||||
if (o >= o) {
|
||||
return 1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun String.inc() : String {
|
||||
operator fun String.inc() : String {
|
||||
if (this == "") {
|
||||
return "done"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user