mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 00:21:47 +00:00
- 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
17 lines
375 B
Kotlin
Vendored
17 lines
375 B
Kotlin
Vendored
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"
|
|
} |