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 Arrays Is Not Possible #6397

Open
IGI-111 opened this issue Aug 7, 2024 · 0 comments · May be fixed by #6941
Open

Dereferencing Arrays Is Not Possible #6397

IGI-111 opened this issue Aug 7, 2024 · 0 comments · May be fixed by #6941
Assignees
Labels
audit-report Related to the audit report

Comments

@IGI-111
Copy link
Contributor

IGI-111 commented Aug 7, 2024

In Sway, developers can create a mutable reference to a variable using something like the following
snippet:

let mut x = 1;
let y = &mut x;
*y = 1

As expected this updates the value of x. However, a mutable reference is not really usable in case of an
array due to limitations in the parsing. In particular, the parser prohibts the use of parentheses on the
left-hand-side of an assignment. The following snippet does not compile:

let mut a = [1, 2];
let mut p = &mut a;
(*p)[1] = 1;
@IGI-111 IGI-111 added the audit-report Related to the audit report label Aug 7, 2024
esdrubal added a commit that referenced this issue Feb 19, 2025
Implements dereferencing as LHS in reassignments for projections.

With this PR we will support:
 - `(*array)[0] = 1`
 - `(*tuple).0 = 1`
 - `(*struct).a = 1`

This allow includes support for nested references.

Fixes #6397
@esdrubal esdrubal linked a pull request Feb 19, 2025 that will close this issue
8 tasks
esdrubal added a commit that referenced this issue Feb 19, 2025
Implements dereferencing as LHS in reassignments for projections.

With this PR we will support:
 - `(*array)[0] = 1`
 - `(*tuple).0 = 1`
 - `(*struct).a = 1`

This allow includes support for nested references.

Fixes #6397
esdrubal added a commit that referenced this issue Feb 19, 2025
Implements dereferencing as LHS in reassignments for projections.

With this PR we will support:
 - `(*array)[0] = 1`
 - `(*tuple).0 = 1`
 - `(*struct).a = 1`

This allow includes support for nested references.

Fixes #6397
esdrubal added a commit that referenced this issue Feb 19, 2025
Implements dereferencing as LHS in reassignments for projections.

With this PR we will support:
 - `(*array)[0] = 1`
 - `(*tuple).0 = 1`
 - `(*struct).a = 1`

This allow includes support for nested references.

Fixes #6397
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Related to the audit report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants