https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
v

vngantk

03/22/2023, 1:14 AM
I have created several DSL frameworks in Kotlin before, and often came to situations where I wanted to overload the assignment “=” operator. I know the reason why the Kotlin team is so reluctant to provide this feature because it could be greatly misused. Can I suggest an alternative? Instead of “=”, Kotlin provides a new operator called “:=“, which has no intrinsic meaning unless you explicitly define an operator function for it. The name of this operator function can be called “assign” or “colonAssign”.
☝️ 1
e

ephemient

03/22/2023, 1:16 AM
v

vngantk

03/22/2023, 1:50 AM
I have tried the plugin. I doesn’t work. Any more information on how to use it?
e

ephemient

03/22/2023, 2:17 AM
from the command-line,
Copy code
package fqdn

annotation class SupportsKotlinAssignmentOverloading

@SupportsKotlinAssignmentOverloading
class Settable<T>(var value: T)

fun <T> Settable<T>.assign(value: T) {
    this.value = value
}
Copy code
$KOTLIN_HOME/bin/kotlinc-jvm -Xplugin=$KOTLIN_HOME/lib/assignment-compiler-plugin.jar -P plugin:org.jetbrains.kotlin.assignment:annotation=fqdn.SupportsKotlinAssignmentOverloading ...
(you can see all the strings in https://github.com/JetBrains/kotlin/blob/master/plugins/assign-plugin/assign-plugin.common/src/org/jetbrains/kotlin/assignment/plugin/AssignmentPluginNames.kt)
🙏 1
a

asdf asdf

03/22/2023, 3:48 AM
Agree with this a lot, there's been several times w/ DSLs where I find it to be useful to overload =. The assignment plugin seems cool, but I couldn't find a lot of documentation on how to use it
e

elizarov

03/22/2023, 9:50 PM
@asdf asdf It would be great if you add use-cases with your DSLs to the KEEP.
33 Views