kotlin
kotlin copied to clipboard
Experimental support for assign operator overload
This PR adds experimental support for assign operator overload. Operator can be enabled with -Xassign-operator
. Operator behaves similar to +=
operator.
It's implemented for F1.0 frontend and FIR frontend.
There are two issues that I know about but I didn't resolve for F1.0 frontend yet:
- rhs of assign can be resolved twice (performance issue)
- Case with smartcast/nullable extension operator with safe call, e.g.:
data class Foo(val x: Container)
data class Container(var value: String)
operator fun Container.assign(value: String) {
}
operator fun Container.plusAssign(value: String) {
}
fun test() {
val nullCheck: Foo? = null
// Old frontend
// `=` diagnostics should be the same as `+=`
<!VAL_REASSIGNMENT!>nullCheck?.x<!> = <!TYPE_MISMATCH!>"Fail"<!>
<!DEBUG_INFO_SMARTCAST!>nullCheck?.x<!> <!NULLABLE_EXTENSION_OPERATOR_WITH_SAFE_CALL_RECEIVER!>+=<!> "Fail"
}
Let me know if you prefer that I squash commits, or if I can do something to make tests more readable.
Thanks for your contribution! It would be great to rebase branch on master (currently we have some conflicts). Also it would be great to group commits somehow (squash all-in-one as the simplest idea, or, for example, leave FE10/FIR/backend changes in separate commits). At least commits like "small code cleanup", "remove unintentionally added file" should be squashed.
Ok, I will try. I think I can group commits in some way, at least to separate fe10 and fir.
I think this should be a bit easier to review:
- first commit has main changes for FIR
- second one has main changes for FE10
- third commit is some polishing: puts changes for FIR behind a feature flag, removes delegate assign operator constraint for FE10 and adds additional tests/adjusts some tests
This is not relevant anymore.