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

Return constant reference on query of member type #172

Conversation

Lai-YT
Copy link
Collaborator

@Lai-YT Lai-YT commented Jul 5, 2024

Since the MemberType function is a query function, it should not have to clone the type.
Note that the function is no longer noexcept after the change. Originally, it returned the unknown type when the id was not a member of the record. However, since we cannot make up such an unknown type as a temporary object and return its reference (undefined behavior), we have to throw an exception. This is acceptable because the type checker should already ensure that the member exists, thus querying with a non-existing id indicates some internal errors.

@Lai-YT Lai-YT added the refactor label Jul 5, 2024
@Lai-YT Lai-YT requested a review from leewei05 July 5, 2024 16:40
@Lai-YT Lai-YT self-assigned this Jul 5, 2024
Since the `MemberType` function is a query function, it should not have
to clone the type. Note that the function is no longer `noexcept` after
the change. Originally, it returned the `unknown` type when the `id` was
not a member of the record. However, since we cannot make up such an
unknown type as a temporary object and return its reference (undefined
behavior), we have to throw an exception. This is acceptable because the
type checker should already ensure that the member exists, thus querying
with a non-existing `id` indicates some internal errors.
@Lai-YT Lai-YT force-pushed the return-constant-reference-on-query-of-member-type branch from 82eddcd to 3454998 Compare July 5, 2024 16:48
Copy link
Contributor

@leewei05 leewei05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@leewei05 leewei05 merged commit 1f48b64 into fruits-lab:main Jul 6, 2024
4 checks passed
@Lai-YT Lai-YT deleted the return-constant-reference-on-query-of-member-type branch July 6, 2024 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants