Fix tests: "infix modifier required" and "operator modifier required" errors
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
operator fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
operator fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
this[index1 + index2] = elem
|
this[index1 + index2] = elem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
operator fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
operator fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
this[index1 + index2] = elem
|
this[index1 + index2] = elem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
|
|
||||||
fun HashMap<String, Int?>.set(index: String, elem: Int?) {
|
operator fun HashMap<String, Int?>.set(index: String, elem: Int?) {
|
||||||
this.put(index, elem)
|
this.put(index, elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -43,16 +43,16 @@ fun box() : String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StrangeArray<T>(size: Int, private var defaultValue: T) {
|
class StrangeArray<T>(size: Int, private var defaultValue: T) {
|
||||||
fun get(index: Int): T = defaultValue
|
operator fun get(index: Int): T = defaultValue
|
||||||
fun set(index: Int, v: T) {
|
operator fun set(index: Int, v: T) {
|
||||||
defaultValue = v
|
defaultValue = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StrangeIntArray(size: Int) {
|
class StrangeIntArray(size: Int) {
|
||||||
private var defaultValue = 0
|
private var defaultValue = 0
|
||||||
fun get(index: Int): Int = defaultValue
|
operator fun get(index: Int): Int = defaultValue
|
||||||
fun set(index: Int, v: Int) {
|
operator fun set(index: Int, v: Int) {
|
||||||
defaultValue = v
|
defaultValue = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
fun String.get(vararg value: Any) : String {
|
operator fun String.get(vararg value: Any) : String {
|
||||||
return if (value[0] == 44 && value[1] == "example") "OK" else "fail"
|
return if (value[0] == 44 && value[1] == "example") "OK" else "fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.get(vararg value: Any) : Int {
|
operator fun Int.get(vararg value: Any) : Int {
|
||||||
return if (value[0] == 44 && value[1] == "example") 1 else 0
|
return if (value[0] == 44 && value[1] == "example") 1 else 0
|
||||||
}
|
}
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun <K, V> MutableMap<K, V>.set(k : K, v : V) = put(k, v)
|
operator fun <K, V> MutableMap<K, V>.set(k : K, v : V) = put(k, v)
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
val map = HashMap<String,String>()
|
val map = HashMap<String,String>()
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
|
operator fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
|
||||||
fun IntArray.get(index: Long) = this[index.toInt()]
|
operator fun IntArray.get(index: Long) = this[index.toInt()]
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
var l = IntArray(1)
|
var l = IntArray(1)
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
fun box(): String {
|
|
||||||
val a1: Byte = 1 plus 1
|
|
||||||
val a2: Short = 1 plus 1
|
|
||||||
val a3: Int = 1 plus 1
|
|
||||||
val a4: Long = 1 plus 1
|
|
||||||
val a5: Double = 1.0 plus 1
|
|
||||||
val a6: Float = 1f plus 1
|
|
||||||
val a7: Char = 'A' plus 1
|
|
||||||
val a8: Int = 'B' minus 'A'
|
|
||||||
|
|
||||||
if (a1 != 2.toByte()) return "fail 1"
|
|
||||||
if (a2 != 2.toShort()) return "fail 2"
|
|
||||||
if (a3 != 2) return "fail 3"
|
|
||||||
if (a4 != 2L) return "fail 4"
|
|
||||||
if (a5 != 2.0) return "fail 5"
|
|
||||||
if (a6 != 2f) return "fail 6"
|
|
||||||
if (a7 != 'B') return "fail 7"
|
|
||||||
if (a8 != 1) return "fail 8"
|
|
||||||
|
|
||||||
return "OK"
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
fun box(): String {
|
|
||||||
val a1: Any = 1.toByte() plus 1
|
|
||||||
val a2: Any = 1.toShort() plus 1
|
|
||||||
val a3: Any = 1 plus 1
|
|
||||||
val a4: Any = 1L plus 1
|
|
||||||
val a5: Any = 1.0 plus 1
|
|
||||||
val a6: Any = 1f plus 1
|
|
||||||
val a7: Any = 'A' plus 1
|
|
||||||
val a8: Any = 'B' minus 'A'
|
|
||||||
|
|
||||||
if (a1 !is Int || a1 != 2) return "fail 1"
|
|
||||||
if (a2 !is Int || a2 != 2) return "fail 2"
|
|
||||||
if (a3 !is Int || a3 != 2) return "fail 3"
|
|
||||||
if (a4 !is Long || a4 != 2L) return "fail 4"
|
|
||||||
if (a5 !is Double || a5 != 2.0) return "fail 5"
|
|
||||||
if (a6 !is Float || a6 != 2f) return "fail 6"
|
|
||||||
if (a7 !is Char || a7 != 'B') return "fail 7"
|
|
||||||
if (a8 !is Int || a8 != 1) return "fail 8"
|
|
||||||
|
|
||||||
return "OK"
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
fun box(): String {
|
|
||||||
val a1: Byte? = 1 plus 1
|
|
||||||
val a2: Short? = 1 plus 1
|
|
||||||
val a3: Int? = 1 plus 1
|
|
||||||
val a4: Long? = 1 plus 1
|
|
||||||
val a5: Double? = 1.0 plus 1
|
|
||||||
val a6: Float? = 1f plus 1
|
|
||||||
val a7: Char? = 'A' plus 1
|
|
||||||
val a8: Int? = 'B' minus 'A'
|
|
||||||
|
|
||||||
if (a1!! != 2.toByte()) return "fail 1"
|
|
||||||
if (a2!! != 2.toShort()) return "fail 2"
|
|
||||||
if (a3!! != 2) return "fail 3"
|
|
||||||
if (a4!! != 2L) return "fail 4"
|
|
||||||
if (a5!! != 2.0) return "fail 5"
|
|
||||||
if (a6!! != 2f) return "fail 6"
|
|
||||||
if (a7!! != 'B') return "fail 7"
|
|
||||||
if (a8!! != 1) return "fail 8"
|
|
||||||
|
|
||||||
return "OK"
|
|
||||||
}
|
|
||||||
+1
-1
@@ -4,5 +4,5 @@ fun box(): String {
|
|||||||
val r = object : Runnable {
|
val r = object : Runnable {
|
||||||
override fun run() {}
|
override fun run() {}
|
||||||
}
|
}
|
||||||
return if (foo(r) identityEquals r) "OK" else "Fail"
|
return if (foo(r).identityEquals(r)) "OK" else "Fail"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,5 +4,5 @@ fun box(): String {
|
|||||||
val r = object : Runnable {
|
val r = object : Runnable {
|
||||||
override fun run() {}
|
override fun run() {}
|
||||||
}
|
}
|
||||||
return if (foo(r) identityEquals r) "OK" else "Fail"
|
return if (foo(r).identityEquals(r)) "OK" else "Fail"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
class MyList<T>() {
|
class MyList<T>() {
|
||||||
var value: T? = null
|
var value: T? = null
|
||||||
|
|
||||||
fun get(index: Int): T = value!!
|
operator fun get(index: Int): T = value!!
|
||||||
|
|
||||||
fun set(index: Int, value: T) { this.value = value }
|
operator fun set(index: Int, value: T) { this.value = value }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
class IntRange {
|
class IntRange {
|
||||||
fun contains(a: Int) = (1..2).contains(a)
|
operator fun contains(a: Int) = (1..2).contains(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
class C() {
|
class C() {
|
||||||
fun rangeTo(i: Int) = IntRange()
|
operator fun rangeTo(i: Int) = IntRange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
fun <K, V> MutableMap<K, V>.set(key : K, value : V) = put(key, value)
|
operator fun <K, V> MutableMap<K, V>.set(key : K, value : V) = put(key, value)
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
fun Int?.inc() : Int { if (this != null) return this.inc() else throw NullPointerException() }
|
operator fun Int?.inc() : Int { if (this != null) return this.inc() else throw NullPointerException() }
|
||||||
|
|
||||||
public fun box() : String {
|
public fun box() : String {
|
||||||
var i : Int? = 10
|
var i : Int? = 10
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
fun Int?.inc() = this!!.inc()
|
operator fun Int?.inc() = this!!.inc()
|
||||||
|
|
||||||
public fun box() : String {
|
public fun box() : String {
|
||||||
var i : Int? = 10
|
var i : Int? = 10
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
fun Int.plus(a: Int?) = this + a!!
|
operator fun Int.plus(a: Int?) = this + a!!
|
||||||
|
|
||||||
public open class PerfectNumberFinder() {
|
public open class PerfectNumberFinder() {
|
||||||
open public fun isPerfect(number : Int) : Boolean {
|
open public fun isPerfect(number : Int) : Boolean {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class ArrayWrapper<T>() {
|
|||||||
contents.add(item)
|
contents.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
operator fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||||
val result = ArrayWrapper<T>()
|
val result = ArrayWrapper<T>()
|
||||||
result.contents.addAll(contents)
|
result.contents.addAll(contents)
|
||||||
result.contents.addAll(b.contents)
|
result.contents.addAll(b.contents)
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ class ArrayWrapper<T>() {
|
|||||||
contents.add(item)
|
contents.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun plusAssign(rhs: ArrayWrapper<T>) {
|
operator fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||||
contents.addAll(rhs.contents)
|
contents.addAll(rhs.contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
operator fun get(index: Int): T {
|
||||||
return contents.get(index)!!
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ class ArrayWrapper<T>() {
|
|||||||
contents.add(item)
|
contents.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
operator fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||||
val result = ArrayWrapper<T>()
|
val result = ArrayWrapper<T>()
|
||||||
result.contents.addAll(contents)
|
result.contents.addAll(contents)
|
||||||
result.contents.addAll(rhs.contents)
|
result.contents.addAll(rhs.contents)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
operator fun get(index: Int): T {
|
||||||
return contents.get(index)!!
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ class ArrayWrapper<T>() {
|
|||||||
contents.add(item)
|
contents.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
operator fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||||
val result = ArrayWrapper<T>()
|
val result = ArrayWrapper<T>()
|
||||||
result.contents.addAll(contents)
|
result.contents.addAll(contents)
|
||||||
result.contents.addAll(rhs.contents)
|
result.contents.addAll(rhs.contents)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
operator fun get(index: Int): T {
|
||||||
return contents.get(index)!!
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ class ArrayWrapper<T>() {
|
|||||||
contents.add(item)
|
contents.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun minus(): ArrayWrapper<T> {
|
operator fun unaryMinus(): ArrayWrapper<T> {
|
||||||
val result = ArrayWrapper<T>()
|
val result = ArrayWrapper<T>()
|
||||||
result.contents.addAll(contents)
|
result.contents.addAll(contents)
|
||||||
Collections.reverse(result.contents)
|
Collections.reverse(result.contents)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
operator fun get(index: Int): T {
|
||||||
return contents.get(index)!!
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ open class A(val s: Int) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.foo(s: Int): Int {
|
infix fun Int.foo(s: Int): Int {
|
||||||
return this + s
|
return this + s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var index = 0
|
var index = 0
|
||||||
|
|
||||||
interface IterableIterator : Iterator<Int> {
|
interface IterableIterator : Iterator<Int> {
|
||||||
fun iterator(): Iterator<Int> = this
|
operator fun iterator(): Iterator<Int> = this
|
||||||
}
|
}
|
||||||
|
|
||||||
val iterator = object : IterableIterator {
|
val iterator = object : IterableIterator {
|
||||||
|
|||||||
+3
-3
@@ -6,9 +6,9 @@ class C {
|
|||||||
|
|
||||||
class X {
|
class X {
|
||||||
var hasNext = true
|
var hasNext = true
|
||||||
fun It.hasNext() = if (hasNext) {hasNext = false; true} else false
|
operator fun It.hasNext() = if (hasNext) {hasNext = false; true} else false
|
||||||
fun It.next() = 5
|
operator fun It.next() = 5
|
||||||
fun C.iterator(): It = It()
|
operator fun C.iterator(): It = It()
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
for (i in C()) {
|
for (i in C()) {
|
||||||
|
|||||||
+3
-3
@@ -1,14 +1,14 @@
|
|||||||
class It {
|
class It {
|
||||||
fun next() = 5
|
operator fun next() = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
fun iterator(): It = It()
|
operator fun iterator(): It = It()
|
||||||
}
|
}
|
||||||
|
|
||||||
class X {
|
class X {
|
||||||
var hasNext = true
|
var hasNext = true
|
||||||
fun It.hasNext() = if (hasNext) {hasNext = false; true} else false
|
operator fun It.hasNext() = if (hasNext) {hasNext = false; true} else false
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
for (i in C()) {
|
for (i in C()) {
|
||||||
|
|||||||
+3
-3
@@ -1,14 +1,14 @@
|
|||||||
class It {
|
class It {
|
||||||
var hasNext = true
|
var hasNext = true
|
||||||
fun hasNext() = if (hasNext) {hasNext = false; true} else false
|
operator fun hasNext() = if (hasNext) {hasNext = false; true} else false
|
||||||
}
|
}
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
fun iterator(): It = It()
|
operator fun iterator(): It = It()
|
||||||
}
|
}
|
||||||
|
|
||||||
class X {
|
class X {
|
||||||
fun It.next() = 5
|
operator fun It.next() = 5
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
for (i in C()) {
|
for (i in C()) {
|
||||||
|
|||||||
@@ -92,23 +92,23 @@ class MyCollection2(): Iterable<Int> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyCollection3() {
|
class MyCollection3() {
|
||||||
fun iterator() = MyIterator()
|
operator fun iterator() = MyIterator()
|
||||||
|
|
||||||
class MyIterator() {
|
class MyIterator() {
|
||||||
var k : Int = 5
|
var k : Int = 5
|
||||||
|
|
||||||
fun next() : Int? = k--
|
operator fun next() : Int? = k--
|
||||||
fun hasNext() : Boolean = k > 0
|
operator fun hasNext() : Boolean = k > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyCollection4() {
|
class MyCollection4() {
|
||||||
fun iterator() = MyIterator()
|
operator fun iterator() = MyIterator()
|
||||||
|
|
||||||
class MyIterator() {
|
class MyIterator() {
|
||||||
var k : Int = 5
|
var k : Int = 5
|
||||||
|
|
||||||
fun next() : Int = k--
|
operator fun next() : Int = k--
|
||||||
fun hasNext() = k > 0
|
operator fun hasNext() = k > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun Int.contains(i : Int) = true
|
operator fun Int.contains(i : Int) = true
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
when (1) {
|
when (1) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class MyRange1() : Range<Int> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyRange2() {
|
class MyRange2() {
|
||||||
fun contains(item: Int) = true
|
operator fun contains(item: Int) = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
fun <T> ArrayList<T>.add3(el: T) = add(el)
|
infix fun <T> ArrayList<T>.add3(el: T) = add(el)
|
||||||
|
|
||||||
fun test(list: ArrayList<Int>) {
|
fun test(list: ArrayList<Int>) {
|
||||||
for (i in 1..10) {
|
for (i in 1..10) {
|
||||||
@@ -10,12 +10,12 @@ class A() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> ArrayList<T>.add2(el: T) = add(el)
|
infix fun <T> ArrayList<T>.add2(el: T) = add(el)
|
||||||
|
|
||||||
fun box() : String{
|
fun box() : String{
|
||||||
var list = ArrayList<Int>()
|
var list = ArrayList<Int>()
|
||||||
for (i in 1..10) {
|
for (i in 1..10) {
|
||||||
list add i
|
list.add(i)
|
||||||
list add2 i
|
list add2 i
|
||||||
}
|
}
|
||||||
A().test(list)
|
A().test(list)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class A() {
|
class A() {
|
||||||
fun action() = "OK"
|
fun action() = "OK"
|
||||||
|
|
||||||
fun infix(a: String) = "O" + a
|
infix fun infix(a: String) = "O" + a
|
||||||
|
|
||||||
val property = "OK"
|
val property = "OK"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ var result = "Fail"
|
|||||||
|
|
||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.plusAssign(a: A, s: String = "OK") {
|
operator fun A.plusAssign(a: A, s: String = "OK") {
|
||||||
result = s
|
result = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -2,7 +2,7 @@ var result = "Fail"
|
|||||||
|
|
||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.plus(a: A, s: String = "OK"): A {
|
operator fun A.plus(a: A, s: String = "OK"): A {
|
||||||
result = s
|
result = s
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
fun Int.foo(o: String, k: String = "K") = o + k
|
infix fun Int.foo(o: String, k: String = "K") = o + k
|
||||||
|
|
||||||
fun box() = 42 foo "O"
|
fun box() = 42 foo "O"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.plus(i: A, ok: String = "OK") = ok
|
operator fun A.plus(i: A, ok: String = "OK") = ok
|
||||||
|
|
||||||
fun box() = A() + A()
|
fun box() = A() + A()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.contains(i: A, actual: Boolean = true) = actual
|
operator fun A.contains(i: A, actual: Boolean = true) = actual
|
||||||
|
|
||||||
fun box() = if (A() in A()) "OK" else "Fail"
|
fun box() = if (A() in A()) "OK" else "Fail"
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import kotlin.reflect.KProperty
|
|||||||
// KT-5612
|
// KT-5612
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
public fun getValue(thisRef: Any?, prop: KProperty<*>): String {
|
operator fun getValue(thisRef: Any?, prop: KProperty<*>): String {
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class B {
|
class B {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class AImpl {
|
class AImpl {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = Derived()
|
var inner = Derived()
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Derived {
|
operator fun getValue(t: Any?, p: KProperty<*>): Derived {
|
||||||
inner = Derived(inner.a + "-get")
|
inner = Derived(inner.a + "-get")
|
||||||
return inner
|
return inner
|
||||||
}
|
}
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Base) { inner = Derived(inner.a + "-" + i.a + "-set") }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Base) { inner = Derived(inner.a + "-" + i.a + "-set") }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>, s: String = ""): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>, s: String = ""): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val prop: Int by Delegate()
|
val prop: Int by Delegate()
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class A {
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo() = Delegate()
|
fun foo() = Delegate()
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
val p = Delegate()
|
val p = Delegate()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: A, p: KProperty<*>): Int = 1
|
operator fun getValue(t: A, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val A.prop: Int by Delegate()
|
val A.prop: Int by Delegate()
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: F.A, p: KProperty<*>): Int = 1
|
operator fun getValue(t: F.A, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class F {
|
class F {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate<T>(var inner: T) {
|
class Delegate<T>(var inner: T) {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): T = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): T = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import kotlin.reflect.KProperty
|
|||||||
class Delegate {
|
class Delegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
val prop: Int by Delegate()
|
val prop: Int by Delegate()
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ class Delegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
val prop: Int by Delegate()
|
val prop: Int by Delegate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
interface A {
|
interface A {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate<T>(var inner: T) {
|
class Delegate<T>(var inner: T) {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): T = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): T = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate<T>(var inner: T) {
|
class Delegate<T>(var inner: T) {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): T = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): T = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
+6
-6
@@ -18,18 +18,18 @@ val metadatas = IdentityHashMap<KProperty<*>, Unit>()
|
|||||||
fun record(p: KProperty<*>) = metadatas.put(p, Unit)
|
fun record(p: KProperty<*>) = metadatas.put(p, Unit)
|
||||||
|
|
||||||
object IntHandler {
|
object IntHandler {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int { record(p); return 42 }
|
operator fun getValue(t: Any?, p: KProperty<*>): Int { record(p); return 42 }
|
||||||
fun setValue(t: Any?, p: KProperty<*>, value: Int) { record(p) }
|
operator fun setValue(t: Any?, p: KProperty<*>, value: Int) { record(p) }
|
||||||
}
|
}
|
||||||
|
|
||||||
object AnyHandler {
|
object AnyHandler {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Any? { record(p); return 3.14 }
|
operator fun getValue(t: Any?, p: KProperty<*>): Any? { record(p); return 3.14 }
|
||||||
fun setValue(t: Any?, p: KProperty<*>, value: Any?) { record(p) }
|
operator fun setValue(t: Any?, p: KProperty<*>, value: Any?) { record(p) }
|
||||||
}
|
}
|
||||||
|
|
||||||
object StringHandler {
|
object StringHandler {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): String { record(p); return p.name }
|
operator fun getValue(t: Any?, p: KProperty<*>): String { record(p); return p.name }
|
||||||
fun setValue(t: Any?, p: KProperty<*>, value: String) { record(p) }
|
operator fun setValue(t: Any?, p: KProperty<*>, value: String) { record(p) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
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) { inner = i }
|
operator fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
var prop: Int by Delegate()
|
var prop: Int by Delegate()
|
||||||
|
|||||||
+2
-2
@@ -2,11 +2,11 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
|
|
||||||
var prop: Int by Delegate()
|
var prop: Int by Delegate()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val prop: Int by Delegate()
|
val prop: Int by Delegate()
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
var prop: Int by Delegate()
|
var prop: Int by Delegate()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate<T>(val f: (T) -> Int) {
|
class Delegate<T>(val f: (T) -> Int) {
|
||||||
fun getValue(t: T, p: KProperty<*>): Int = f(t)
|
operator fun getValue(t: T, p: KProperty<*>): Int = f(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
val p = Delegate<A> { t -> t.foo() }
|
val p = Delegate<A> { t -> t.foo() }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): String {
|
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||||
p.parameters
|
p.parameters
|
||||||
p.returnType
|
p.returnType
|
||||||
p.annotations
|
p.annotations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var inner = 1
|
var inner = 1
|
||||||
fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||||
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
fun getValue(t: Any?, vararg p: KProperty<*>): Int = 1
|
operator fun getValue(t: Any?, vararg p: KProperty<*>): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val prop: Int by Delegate()
|
val prop: Int by Delegate()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
fun String.plus() {
|
operator fun String.unaryPlus() {
|
||||||
sb.append(this)
|
sb.append(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class A {
|
class A {
|
||||||
private val sb: StringBuilder = StringBuilder()
|
private val sb: StringBuilder = StringBuilder()
|
||||||
|
|
||||||
fun String.plus() {
|
operator fun String.unaryPlus() {
|
||||||
sb.append(this)
|
sb.append(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ var result = ""
|
|||||||
fun result(r: String) { result = r }
|
fun result(r: String) { result = r }
|
||||||
|
|
||||||
object Foo {
|
object Foo {
|
||||||
private fun String.plus() = "(" + this + ")"
|
private operator fun String.unaryPlus() = "(" + this + ")"
|
||||||
|
|
||||||
fun foo() = { result(+"Stuff") }()
|
fun foo() = { result(+"Stuff") }()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ var result = "Fail"
|
|||||||
|
|
||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.inc(s: String = "OK"): A {
|
operator fun A.inc(s: String = "OK"): A {
|
||||||
result = s
|
result = s
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import java.util.*
|
|||||||
class Template() {
|
class Template() {
|
||||||
val collected = ArrayList<String>()
|
val collected = ArrayList<String>()
|
||||||
|
|
||||||
fun String.plus() {
|
operator fun String.unaryPlus() {
|
||||||
collected.add(this@plus)
|
collected.add(this@unaryPlus)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun <T> T.mustBe(t : T) {
|
infix fun <T> T.mustBe(t : T) {
|
||||||
assert("$this must be $t") {this == t}
|
assert("$this must be $t") {this == t}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ class A {
|
|||||||
val char: Char = '0'
|
val char: Char = '0'
|
||||||
val bool: Boolean = false
|
val bool: Boolean = false
|
||||||
|
|
||||||
fun invoke() {
|
operator fun invoke() {
|
||||||
int.valProp
|
int.valProp
|
||||||
long.valProp
|
long.valProp
|
||||||
short.valProp
|
short.valProp
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ class A {
|
|||||||
var char: Char = '0'
|
var char: Char = '0'
|
||||||
var bool: Boolean = false
|
var bool: Boolean = false
|
||||||
|
|
||||||
fun invoke() {
|
operator fun invoke() {
|
||||||
int.varProp = int
|
int.varProp = int
|
||||||
long.varProp = long
|
long.varProp = long
|
||||||
short.varProp = short
|
short.varProp = short
|
||||||
|
|||||||
+2
-2
@@ -3,14 +3,14 @@ import kotlin.reflect.KProperty
|
|||||||
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
|
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
|
||||||
private var value: T? = null
|
private var value: T? = null
|
||||||
|
|
||||||
public open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
|
operator open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = initializer()
|
value = initializer()
|
||||||
}
|
}
|
||||||
return value!!
|
return value!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
|
operator open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
|
||||||
value = svalue
|
value = svalue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class MyString {
|
class MyString {
|
||||||
var s = ""
|
var s = ""
|
||||||
fun plus(x : String) : MyString {
|
operator fun plus(x : String) : MyString {
|
||||||
s += x
|
s += x
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
class MyString {
|
class MyString {
|
||||||
var s = ""
|
var s = ""
|
||||||
fun plus(x : String) : MyString {
|
operator fun plus(x : String) : MyString {
|
||||||
s += x
|
s += x
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class MyString {
|
class MyString {
|
||||||
var s = ""
|
var s = ""
|
||||||
fun plus(x : String) : MyString {
|
operator fun plus(x : String) : MyString {
|
||||||
s += x
|
s += x
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class MyString {
|
class MyString {
|
||||||
var s = ""
|
var s = ""
|
||||||
fun plus(x : String) : MyString {
|
operator fun plus(x : String) : MyString {
|
||||||
s += x
|
s += x
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
return justPrint(9 compareTo 4)
|
return justPrint(9.compareTo(4))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun justPrint(value: Int): String {
|
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) {
|
if (this > 1) {
|
||||||
return (this - 1) test x
|
return (this - 1) test x
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class A
|
class A
|
||||||
|
|
||||||
class B {
|
class B {
|
||||||
fun A.invoke() = "##"
|
operator fun A.invoke() = "##"
|
||||||
fun A.invoke(i: Int) = "#${i}"
|
operator fun A.invoke(i: Int) = "#${i}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo() = A()
|
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)
|
fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i)
|
||||||
|
|
||||||
class Method {
|
class Method {
|
||||||
fun invoke(i: Int) = i
|
operator fun invoke(i: Int) = i
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test3(method: Method, i: Int) = method.invoke(i)
|
fun test3(method: Method, i: Int) = method.invoke(i)
|
||||||
@@ -14,7 +14,7 @@ fun test4(method: Method, i: Int) = method(i)
|
|||||||
|
|
||||||
class Method2 {}
|
class Method2 {}
|
||||||
|
|
||||||
fun Method2.invoke(s: String) = s
|
operator fun Method2.invoke(s: String) = s
|
||||||
|
|
||||||
fun test5(method2: Method2, s: String) = method2(s)
|
fun test5(method2: Method2, s: String) = method2(s)
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
//KT-2728 Can't compile A()()
|
//KT-2728 Can't compile A()()
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
fun invoke() = "##"
|
operator fun invoke() = "##"
|
||||||
fun invoke(i: Int) = "#${i}"
|
operator fun invoke(i: Int) = "#${i}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo() = A()
|
fun foo() = A()
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ class Bad(val a: () -> Int) {
|
|||||||
|
|
||||||
fun test(): Int = a()
|
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
|
//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 {
|
try {
|
||||||
return this()
|
return this()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
public class A(val s: String) {
|
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)
|
fun x(y : String) : A = A(y)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//KT-3631 String.invoke doesn't work with literals
|
//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"
|
fun box() = if ("a"(12) == "a12") "OK" else "fail"
|
||||||
@@ -5,7 +5,7 @@ open class A {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class B {
|
class B {
|
||||||
fun invoke(f: B.() -> Unit) = 2
|
operator fun invoke(f: B.() -> Unit) = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
open class C
|
open class C
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//KT-3821 Invoke convention doesn't work for `this`
|
//KT-3821 Invoke convention doesn't work for `this`
|
||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
fun invoke() = 42
|
operator fun invoke() = 42
|
||||||
fun foo() = this() // Expecting a function type, but found A
|
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 {
|
return YieldingIterable {
|
||||||
val iterator = this.iterator()
|
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 {
|
return YieldingIterable {
|
||||||
val iterator = this.iterator();
|
val iterator = this.iterator();
|
||||||
|
|||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
interface MyIterator<T> {
|
interface MyIterator<T> {
|
||||||
fun hasNext() : Boolean
|
operator fun hasNext() : Boolean
|
||||||
fun next() : T
|
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
|
var hasNext = this@iterator != null
|
||||||
private set
|
private set
|
||||||
override fun hasNext() = hasNext
|
override fun hasNext() = hasNext
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
fun foo(): Int {
|
fun foo(): Int {
|
||||||
val a = "test"
|
val a = "test"
|
||||||
val b = "test"
|
val b = "test"
|
||||||
return a compareTo b
|
return a.compareTo(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String = if(foo() == 0) "OK" else "Fail"
|
fun box(): String = if(foo() == 0) "OK" else "Fail"
|
||||||
|
|||||||
+3
-3
@@ -7,15 +7,15 @@ class B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun test1(a: A): Int {
|
fun test1(a: A): Int {
|
||||||
return a[1]
|
return a.get(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test2(a: A): Int {
|
fun test2(a: A): Int {
|
||||||
return a[1, 2]
|
return a.get(1, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test3(b: B): Int {
|
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 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 + 1 } != 3) return "Fail 1"
|
||||||
if (foo { it plus 1} != 3) return "Fail 2"
|
if (foo { it plus 1 } != 3) return "Fail 2"
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
fun Int.foo(a: Int): Int = a + 2
|
infix fun Int.foo(a: Int): Int = a + 2
|
||||||
|
|
||||||
val s = object {
|
val s = object {
|
||||||
fun test(): Int {
|
fun test(): Int {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class T(val value: Int) {
|
|||||||
|
|
||||||
fun local() : Int {
|
fun local() : Int {
|
||||||
|
|
||||||
fun T.get(s: Int): Int {
|
operator fun T.get(s: Int): Int {
|
||||||
return s * this.value
|
return s * this.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
open class T(var value: Int) {}
|
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
|
value += s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user