Skip to content

stage2: Copied optional payload aliases with source #13069

@topolarity

Description

@topolarity

Zig Version

0.10.0-dev.4217+9d8cdb855

Steps to Reproduce

const std = @import("std");
const expect = std.testing.expect;

test {
    var opt_x: ?[3]f32 = [_]f32{ 0.0 } ** 3;

    const x = opt_x.?;
    opt_x.?[0] = 15.0;

    try expect(x[0] == 0.0);
}

Requires -O ReleaseFast to trigger. Problem is that .optional_payload elides copies unconditionally for by-ref types.

Expected Behavior

Test should pass.

Actual Behavior

$ zig test test.zig -O ReleaseFast
Test [1/1] test_0... FAIL (TestUnexpectedResult)
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
/Users/toadman667/repos/zig/zig-cache/o/cd307c2bc32e1f4fbf5988425c58e07c/test

Metadata

Metadata

Assignees

Labels

backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions