Since there's no concrete plugin-priority system, ...
# compiler
c
Since there's no concrete plugin-priority system, I wanted to see if anyone could help me figure out how to design my "overloaded setters" plugin such that it doesn't need to run last. Details in thread.
Basically, the plugin should allow custom setters - both contained and extension - like this:
Copy code
// 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.
All I can think of is to do the exact same thing as
kotlin-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.
But that's forcibly remapping every single assignment to a
setBar
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"
Can anyone think of a way to not remap every single property assignment to a
setBar
function and sort it out later?