[Assign plugin] Add a compiler plugin for overloading assign ('=') operator

This commit is contained in:
Anže Sodja
2022-09-01 07:51:38 +02:00
committed by Dmitriy Novozhilov
parent 6052962f50
commit 09d6dfc8bf
62 changed files with 2822 additions and 6 deletions
@@ -0,0 +1,27 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
data class Task(val input: StringProperty)
fun `should report error if type doesn't match`() {
val task = Task(StringProperty("Fail"))
<!VAL_REASSIGNMENT!>task.input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
fun `should report error if type doesn't match with apply`() {
val task = Task(StringProperty("Fail"))
task.apply {
<!VAL_REASSIGNMENT!>input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
}