Skip to content
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

@call does not work within inline loops #5170

Closed
pfgithub opened this issue Apr 26, 2020 · 3 comments
Closed

@call does not work within inline loops #5170

pfgithub opened this issue Apr 26, 2020 · 3 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

@pfgithub
Copy link
Contributor

pfgithub commented Apr 26, 2020

Zig 0.6.0+d44c9bdbd on Linux x64

When using @call within an inlined loop that loops at least twice, it errors:

./test.zig:13:16: error: cannot assign to constant
        @call(.{}, write, .{}); //<- cannot asssign to constant
               ^
./test.zig:3:29: note: referenced here
pub fn main() anyerror!void {
                            ^
./test.zig:13:16: error: cannot assign to constant
        @call(.{}, write, .{}); //<- cannot asssign to constant
               ^
./test.zig:26:16: error: cannot assign to constant
        @call(.{}, write, .{}); //<- cannot asssign to constant
               ^
./test.zig:26:16: error: cannot assign to constant
        @call(.{}, write, .{}); //<- cannot asssign to constant
               ^

test.zig:

const std = @import("std");
fn write() void {}
pub fn main() anyerror!void {
    @call(.{}, write, .{}); //<- works

    inline for (&[_]u0{}) |a| {
        @call(.{}, write, .{}); //<- works
    }
    inline for (&[_]u0{0}) |a| {
        @call(.{}, write, .{}); //<- works
    }
    inline for (&[_]u0{ 0, 0 }) |a| {
        @call(.{}, write, .{}); //<- cannot asssign to constant
    }

    comptime var i: i64 = 0;
    inline while (i < 0) : (i += 1) {
        @call(.{}, write, .{}); //<- works
    }
    comptime var j: i64 = 0;
    inline while (j < 1) : (j += 1) {
        @call(.{}, write, .{}); //<- works
    }
    comptime var k: i64 = 0;
    inline while (k < 2) : (k += 1) {
        @call(.{}, write, .{}); //<- cannot asssign to constant
    }
}

Expected behaviour: The function call would be inlined (repeated 2 times), and there would be no error.

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

Related to #4639 and #4850

@jwhear
Copy link
Contributor

jwhear commented Nov 16, 2021

Just ran into this. It can be worked around by using a simple wrapper function instead of putting the @call directly in the loop:

fn callWrapper(func: anytype, args: anytype) !void {
    try @call(.{}, func, args);
}

@Vexu
Copy link
Member

Vexu commented Dec 30, 2022

Duplicate of #4639

@Vexu Vexu marked this as a duplicate of #4639 Dec 30, 2022
@Vexu Vexu closed this as completed Dec 30, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 30, 2022
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

5 participants