Skip to content

global variable initialized to a global constant is actually a mutable reference #2855

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

Closed
thejoshwolfe opened this issue Jul 9, 2019 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@thejoshwolfe
Copy link
Contributor

possibly a regression from result location.

const std = @import("std");

const Foo = struct {
    x: i32,
    y: i32,
};

/// should be constant
const c = Foo{ .x = 1, .y = 1 };

/// should be a copy of c, not a reference to it.
var v: Foo = c;

test "asdf" {
    var p = &c;
    std.testing.expect(p.x == c.x);
    // this erroneously modifies c at runtime:
    v.x = 2;
    // comptime c.x is 1, but runtime p.x is actually 2:
    std.testing.expect(p.x == c.x);
}
@thejoshwolfe thejoshwolfe added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jul 9, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Jul 9, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 29, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Apr 1, 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

this works now

Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 29, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 29, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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

3 participants