Skip to content

Unwanted comptime evaluation #4144

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
ikskuh opened this issue Jan 11, 2020 · 1 comment
Closed

Unwanted comptime evaluation #4144

ikskuh opened this issue Jan 11, 2020 · 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

@ikskuh
Copy link
Contributor

ikskuh commented Jan 11, 2020

When using a struct literal in @bitCast, Zig wants to evaluate that literal at comptime:

const T = packed struct {
    val: u8
};
export fn failure(p: u8) u8 {
    return @bitCast(u8, T {
        .val = p, // error: cannot store runtime value in compile time variable
    });
}

// this works
export fn works(p: u8) u8 {
    const t = T {
        .val = p,
    };
    return @bitCast(u8, t);
}

Zig version: 0.5.0+27b290f31

@andrewrk andrewrk added this to the 0.7.0 milestone Jan 26, 2020
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jan 26, 2020
@BarabasGitHub
Copy link
Contributor

BarabasGitHub commented Mar 5, 2020

I guess this is a similar problem?

test "inline for" {
    var a: [4]f32 = undefined;
    inline for (a) |e|{
    }
}

produces

error: cannot store runtime value in compile time variable
    inline for (a) |e|{
                    ^

I don't see why that should be a comptime variable.

Zig version: 0.5.0+378bf1c3b

@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
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 1, 2023
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