Skip to content

Segmentation Fault When Using Anonymous Struct Literal Assignment #23190

Open
@ArielBenichou

Description

@ArielBenichou

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

  1. Create a new Zig project (I've used zig init).
  2. Place the following minimal code into your main.zig:
fn createVec(x: f32, y: f32, z: f32) [3]f32 {
    return .{ x, y, z };
}

var camera = .{
    .pos = createVec(0, 0, 0),
};

pub fn main() !void {
    camera.pos = createVec(0, 1, 0);
}
  1. Build and run the project using zig build run.

Observed Behavior
The program terminates with a segmentation fault:

Segmentation fault at address 0xaaaaaaaaaaaaaaaa
aborting due to recursive panic
run
└─ run zig_seg_fault_anony_lit_struct failure
error: the following command terminated unexpectedly:
/Users/arielbenichou/personal/zig-seg-fault-anonymous-literal-struct/zig-out/bin/zig_seg_fault_anony_lit_struct
Build Summary: 3/5 steps succeeded; 1 failed
run transitive failure
└─ run zig_seg_fault_anony_lit_struct failure
error: the following build command failed with exit code 1:
/Users/arielbenichou/personal/zig-seg-fault-anonymous-literal-struct/.zig-cache/o/0bd88885df425ba4769286815bd940e7/build /Users/arielbenichou/.zvm/0.14.0/zig /Users/arielbenichou/.zvm/0.14.0/lib /Users/arielbenichou/personal/zig-seg-fault-anonymous-literal-struct /Users/arielbenichou/personal/zig-seg-fault-anonymous-literal-struct/.zig-cache /Users/arielbenichou/.cache/zig --seed 0x82075a23 -Z0d899954f16beb30 run

Expected Behavior

Now I understand that Anonymous Struct Literals create comptime fields that can't be modified.

But should it compile at all?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorregressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions