Skip to content

@ptrToInt fails at comptime if expression result is a variable #4375

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
Snektron opened this issue Feb 2, 2020 · 0 comments
Closed

@ptrToInt fails at comptime if expression result is a variable #4375

Snektron opened this issue Feb 2, 2020 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@Snektron
Copy link
Collaborator

Snektron commented Feb 2, 2020

The following snippet fails to compile:

export fn a() usize {
    return comptime blk: {
        const b: u8 = 1;
        const c = @ptrToInt(&b);
        break :blk c;
    };
}
<source>:4:19: error: cannot store runtime value in compile time variable
        const c = @ptrToInt(&b);
                  ^

but if the temporary c is left out:

export fn a() usize {
    return comptime blk: {
        const b: u8 = 1;
        break :blk @ptrToInt(&b);
    };
}

compilation is successful. Note that it does not matter whether c is designated as comptime variable, it yields the same error. Same with assigning an expression to c which is dependent on @ptrToInt(&b).

@andrewrk andrewrk added this to the 0.7.0 milestone Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@SpexGuy SpexGuy added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Mar 21, 2021
@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