cppfront
cppfront copied to clipboard
[BUG] `operator=` returns `out this` parameter
Description
Discussion #626 is related to this bug. The signature of operator= is misleading, because it returns this object but it doesn't have any return value in the signature.
To Reproduce
This is an example:
cls1: type
= {
operator=: (out this) = { /* statements... */ }
}
When I read the signature, I expect operator= not to have any return value, because out parameters are not return values. But operator= returns this object.
The behavior of operator= is like this signature:
cls1: type
= {
operator=: () -> (this) = { /* statements... */ }
//or : () -> cls1 = { /* statements... */ }
//or : () -> type = { /* statements... */ }
}
EDIT: I mean the way we write operator= declaration should reflect this object is a return value.
Additional context
Also UFCS ignores out this in operator=, that's may be misleading when out this is the first parameter. On the other hand, it feels right if this was a return value.
I think we discussed this before, and Herb answered it. Do you happen to have a link to it?
No, this bug is different than that. This bug is about the signature of operator= to be changed to reflect the fact of how UFCS works on operator=.
EDIT:
@JohelEGP, that discussion is #663.
I assume this is one of those cases where the operator= function has a special default of returning this, and because of that special default, you don't need to mention it. I think this fact helps inform the parallel discussion about whether operator= should have a default of out for this if it's not specified. This function is already special in a variety of ways, including generating up to 4 different operations from one definition.