"Inapplicable operator modifier" and "Inapplicable infix modifier" are now errors

This commit is contained in:
Yan Zhulanow
2015-12-25 18:35:02 +03:00
parent f560799bb7
commit 3fa506fd45
67 changed files with 56 additions and 347 deletions
@@ -1,12 +0,0 @@
var result = "Fail"
class A
operator fun A.plusAssign(a: A, s: String = "OK") {
result = s
}
fun box(): String {
A() += A()
return result
}
@@ -1,14 +0,0 @@
var result = "Fail"
class A
operator fun A.plus(a: A, s: String = "OK"): A {
result = s
return this
}
fun box(): String {
var a = A()
a += A()
return result
}
@@ -1,3 +0,0 @@
infix fun Int.foo(o: String, k: String = "K") = o + k
fun box() = 42 foo "O"
@@ -1,5 +0,0 @@
class A
operator fun A.plus(i: A, ok: String = "OK") = ok
fun box() = A() + A()
@@ -1,5 +0,0 @@
class A
operator fun A.contains(i: A, actual: Boolean = true) = actual
fun box() = if (A() in A()) "OK" else "Fail"
@@ -1,11 +0,0 @@
import kotlin.reflect.KProperty
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>, s: String = ""): Int = 1
}
val prop: Int by Delegate()
fun box(): String {
return if(prop == 1) "OK" else "fail"
}
@@ -1,11 +0,0 @@
import kotlin.reflect.KProperty
class Delegate {
operator fun getValue(t: Any?, vararg p: KProperty<*>): Int = 1
}
val prop: Int by Delegate()
fun box(): String {
return if(prop == 1) "OK" else "fail"
}
@@ -1,6 +1,6 @@
open class T(var value: Int) {}
operator fun plusAssign(): T {
fun plusAssign(): T {
operator fun T.plusAssign(s: Int) {
value += s
@@ -1,8 +0,0 @@
class Z {}
fun box(): String {
operator fun Z.plus(s : String, d : String = "K") : String {
return s + d
}
return Z() + "O"
}
@@ -1,12 +0,0 @@
class MyClass
// In principle it is not correct, MyClass? is not a subtype of MyClass
operator fun MyClass.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = i++
return if (j is MyClass && null == i) "OK" else "fail i = $i j = $j"
}
@@ -1,12 +0,0 @@
class MyClass
// In principle it is not correct, MyClass? is not a subtype of MyClass
operator fun MyClass.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = ++i
return if (j == null && null == i) "OK" else "fail i = $i j = $j"
}