Caleb B
11/12/2025, 10:06 PMCaleb B
11/12/2025, 10:08 PM// Foo.kt
class Foo {
@AllowsCustomSetters
var bar: () -> String = {}
fun setBar(value: String) {
bar = { value }
}
}
// ExtMethods.kt
fun Foo.setBar(value: Int) {
bar = value.toString()
}
// Main.kt
val foo = Foo()
foo.bar = "Hello world!"
assert(foo.bar() == "Hello world!")
foo.bar = 0
assert(foo.bar() == "0")
The problem is that when running an AssignmentAltererExtension, I can't see the type information for the RHS of the assignment. So while I can see all of the different types of setBar for the property, I can't make sure I'm invoking one that even exists.Caleb B
11/12/2025, 10:09 PMkotlin-assignment-plugin, which transforms every single assignment targeting an annotated type to the custom setter, and lets the type checker sort it out in the linking phase.Caleb B
11/12/2025, 10:11 PMsetBar call, and then remapping it back to the original setter if it matches the original type. That's a brittle extra step I really don't want to add.
kotlin-assignment-plugin doesn't have to deal with that since it only targets `val`s, so any sets are either "targeting custom" or "completely invalid"Caleb B
11/12/2025, 10:13 PMsetBar function and sort it out later?