Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure valid type name for operators with multiple returns. #796

Merged
merged 6 commits into from
Dec 28, 2023

Conversation

iprtel
Copy link
Contributor

@iprtel iprtel commented Nov 1, 2023

This allows operators to have multiple returns.

To enable multiple returns from a function a new struct is created. That struct is named after the function. If the function is a operator this name contains characters that are invalid for type names.

Consider:

operator*: (this) -> (x:int, y:int)=  {
        x = x_current;
        y = y_current;
        return ;
}

results in

error: expected a type
[build]    53 |         public: [[nodiscard]] auto operator*() const& -> operator*_ret;

@hsutter
Copy link
Owner

hsutter commented Dec 28, 2023

Thanks! I did it just for (), [], and * for now because those seem to be the main use cases (and after I picked those, I noticed they were also the ones you chose to exercise which is at least some confirmation), and I'm happier to rein in the overuse/abuse of operator overloading where types really should normally "do as the ints do" (e.g., < should return a boolean value, not something more complex). But it's easy to expand this in the future for more operators by just adding them to the renaming table.

@hsutter hsutter merged commit 07e00c8 into hsutter:main Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants