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

Edge case where you cannot modify mutable pointer #2672

Closed
Hejsil opened this issue Jun 13, 2019 · 2 comments
Closed

Edge case where you cannot modify mutable pointer #2672

Hejsil opened this issue Jun 13, 2019 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Jun 13, 2019

const S = struct {
    a: u8,
};

test "" {
    const s = &S{ .a = 2 };
    @compileLog(@typeOf(s));
    s.a = 2;
}
| *S
/home/hejsil/repo/zen/test.zen:7:5: error: found compile log statement
    @compileLog(@typeOf(s));
    ^
/home/hejsil/repo/zen/test.zen:8:9: error: cannot assign to constant
    s.a = 2;

As we can see from the error, the @compileLog prints that s is a mutable pointer, yet, you cannot modify it's memory. Change s to be a var instead of const makes this compile.

@andrewrk andrewrk added this to the 0.5.0 milestone Jun 16, 2019
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jun 16, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 11, 2019
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Oct 12, 2021

adding that this works

const S = struct { a: u8 };

test "" {
    var r = S{ .a = 2 };
    const s = &r;
    s.a = 3;
}

@Vexu
Copy link
Member

Vexu commented Dec 8, 2021

Fixed by #4971.

@Vexu Vexu closed this as completed Dec 8, 2021
@Vexu Vexu removed this from the 0.11.0 milestone Dec 8, 2021
@andrewrk andrewrk added this to the 0.6.0 milestone Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants