Files
kotlin/compiler/testData/codegen/box/operatorConventions/remAssignmentOperation.kt
Mikhail Zarechenskiy 97ca51381a 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
2016-12-09 16:43:35 +03:00

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"
}