Gradual migration of operator 'mod' to 'rem'

- Introduce new 'rem' operator convention
 - Prefer 'rem()' to 'mod()' when both are available, even if mod() is a
   member, and rem() -- an extension
 - Place operator 'rem' under the language feature
This commit is contained in:
Mikhail Zarechenskiy
2016-12-05 22:42:16 +03:00
parent 2df9daab1f
commit 97ca51381a
29 changed files with 528 additions and 28 deletions
@@ -0,0 +1,17 @@
class A() {
var x = 5
}
operator fun A.modAssign(y: Int) { throw RuntimeException("mod has been called instead of rem") }
operator fun A.remAssign(y: Int) { x %= y + 1 }
fun box(): String {
val original = A()
val a = original
a %= 2
if (a !== original) return "Fail 1: $a !== $original"
if (a.x != 2) return "Fail 2: ${a.x} != 2"
return "OK"
}
@@ -0,0 +1,18 @@
class A() {
var x = 5
operator fun mod(y: Int) { throw RuntimeException("mod has been called instead of rem") }
operator fun rem(y: Int) { x -= y }
}
fun box(): String {
val a = A()
a % 5
if (a.x != 0) {
return "Fail: a.x(${a.x}) != 0"
}
return "OK"
}
@@ -0,0 +1,13 @@
public final class A {
private field x: int
public method <init>(): void
public final method getX(): int
public final method setX(p0: int): void
}
public final class RemAssignmentOperationKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method modAssign(@org.jetbrains.annotations.NotNull p0: A, p1: int): void
public final static method remAssign(@org.jetbrains.annotations.NotNull p0: A, p1: int): void
}
@@ -0,0 +1,13 @@
public final class A {
private field x: int
public method <init>(): void
public final method getX(): int
public final method mod(p0: int): void
public final method rem(p0: int): void
public final method setX(p0: int): void
}
public final class RemOverModOperationKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}