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

Test "naughty pointer" does not compile #275

Closed
ghost opened this issue Oct 13, 2024 · 1 comment · Fixed by #281
Closed

Test "naughty pointer" does not compile #275

ghost opened this issue Oct 13, 2024 · 1 comment · Fixed by #281

Comments

@ghost
Copy link

ghost commented Oct 13, 2024

I tried the "naughty pointer" test from Language / Pointers and it didn't compile (with Zig 0.13.0):

test "naughty pointer" {
    var x: u16 = 0;
    var y: *u8 = @ptrFromInt(x);
    _ = y;
}

For both variables it said error: local variable is never mutated and note: consider using 'const'.

So I guess instead it should now be:

test "naughty pointer" {
    const x: u16 = 0;
    const y: *u8 = @ptrFromInt(x);
    _ = y;
}

I would have opened a pull request, but I think the output of the test also needs updating (because now it's a different, cleaner message), and my test files wouldn't match yours so it wouldn't look good.

@suba327777
Copy link

suba327777 commented Dec 16, 2024

I think this code needs to be fixed because it didn't compile either.(with Zig 0.13.0)
In variable y, error:local variable is never muted

test "const pointers" {
    const x: u8 = 1;
    var y = &x;
    y.* += 1;
}

So I think it should be modified as follows

test "const pointers" {
    const x: u8 = 1;
    const y = &x;
    y.* += 1;
}

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 a pull request may close this issue.

1 participant