package h trait A {} fun newA(): A = throw Exception() trait Z fun id(t: T): T = t //binary expressions //identifier fun Z.foo(a: A): A = a fun test(z: Z) { z foo newA() val a: A = id(z foo newA()) val b: A = id(z.foo(newA())) use(a, b) } //binary operation expression fun Z.plus(a: A): A = a fun test1(z: Z) { id(z + newA()) val a: A = z + newA() val b: A = z.plus(newA()) val c: A = id(z + newA()) val d: A = id(z.plus(newA())) use(a, b, c, d) } //comparison operation fun Z.compareTo(a: A): Int { use(a); return 1 } fun test2(z: Z) { val a: Boolean = id(z < newA()) val b: Boolean = id(z < newA()) use(a, b) } //'equals' operation fun Z.equals(any: Any): Int { use(any); return 1 } fun test3(z: Z) { z == newA() z == newA() id(z == newA()) id(z == newA()) id(z === newA()) id(z === newA()) } //'in' operation fun test4(collection: Collection>) { id(newA() in collection) id(newA() in collection) } //boolean operations fun toBeOrNot(): Boolean = throw Exception() fun test5() { if (toBeOrNot() && toBeOrNot()) {} if (toBeOrNot() && toBeOrNot()) {} } //use fun use(vararg a: Any?) = a