cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] `operator=` returns `out this` parameter

Open msadeqhe opened this issue 1 year ago • 3 comments
trafficstars

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.

msadeqhe avatar Nov 22 '23 11:11 msadeqhe

I think we discussed this before, and Herb answered it. Do you happen to have a link to it?

JohelEGP avatar Nov 22 '23 11:11 JohelEGP

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.

msadeqhe avatar Nov 22 '23 12:11 msadeqhe

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.

gregmarr avatar Nov 22 '23 15:11 gregmarr