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

Dereferencing operator . on tuple element access #5552

Merged
merged 7 commits into from
Feb 5, 2024

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Feb 5, 2024

Description

This PR implements tuple element access operator . for references. The overall effort related to references is tracked in #5063.

. is defined for references to tuples using this recursive definition: <reference>.<element index> := (*<reference>).<element index>.

This eliminates the need for the dereferencing operator * when working with references to tuples:

let t = (1, 2, 3);

let r = &&&t;

assert((***r).0 == r.0);
let r = &&& ( &&(1, 2), &(3, 4) );
assert(r.0.0 == 1);
assert(r.1.1 == 4);

Additionally, the PR:

  • creates Diagnostic for the TupleIndexOutOfBounds error.
  • harmonizes the appearance of the TupleIndexOutOfBounds error in the element access and reassignments.

Demo

TupleIndexOutOfBounds in element access and reassignments before:

Tuple index out of bounds - Before

New errors:

Tuple index out of bounds - After

Tuple element access requires a tuple

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Feb 5, 2024
@ironcev ironcev self-assigned this Feb 5, 2024
@ironcev ironcev requested review from a team February 5, 2024 10:57
@ironcev ironcev marked this pull request as ready for review February 5, 2024 10:57
@ironcev ironcev requested review from IGI-111 and a team February 5, 2024 13:10
@IGI-111 IGI-111 enabled auto-merge (squash) February 5, 2024 23:26
@IGI-111 IGI-111 merged commit 56b42cb into master Feb 5, 2024
36 checks passed
@IGI-111 IGI-111 deleted the ironcev/dereferencing-operator-tuple-element-access branch February 5, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants