Skip to content

Compiler crash when using stackFallbackAllocator.get() during comptime #21233

@Ratakor

Description

@Ratakor

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Code:

const std = @import("std");
var al_sfa = std.heap.stackFallback(4096, std.heap.page_allocator);
var al = std.ArrayList(u8).init(al_sfa.get());

pub fn main() !void {
    _ = al_sfa;
    _ = al;
}

Output

/lib/zig/std/heap.zig:532:24: error: unable to evaluate comptime expression
                assert(!self.get_called); // `get` called multiple times; instead use `const allocator = stackFallback(N).get();`
                       ^~~~~~~~~~~~~~~~
test.zig:4:43: note: called from here
var al = std.ArrayList(u8).init(al_sfa.get());
                                ~~~~~~~~~~^~

This is due to #18275 because it used to work perfectly fine in 0.11.0.

Expected Behavior

No compilation error or crash from the compilator when using stackFallbackAllocator.get() during comptime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions