I’ve released <https://github.com/vlsi/kotlin-argu...
# compiler
v
I’ve released https://github.com/vlsi/kotlin-argument-expression plugin that captures and passes call argument expression to the downstream function. For instance:
Copy code
class Named<Value>(
    val value: Value,
    @CallerArgumentExpression("value") val name: String = ""
) {
    override fun toString(): String = "Named(value=$value, name='$name')"
}

Named(2+2) // the plugin would transform the call to Named(2+2, "2+2")
It might be helpful for tests, preconditions, asserts, etc, so you can have better outputs with almost no overhead.
👍🏻 1
🙏 3
👍 5
mind blown 2
👀 1
I’ve raised a question to junit5 folks to see what they think of supporting that in junit by default: https://github.com/junit-team/junit5/issues/3176
e
Wouldn't the library consumer need to add the compiler plugin as well? I suppose it wouldn't work out of the box?
v
that is right. Consumer should add the compiler plugin. However, if the library author adds the annotations, then it would be automatically supported by the plugin, and the library author could have better control of the way extra arguments are passed
Technically speaking, the plugin is not needed at producer side, however, it would perform validation there, so the author can detect misplaced annotations