-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavioruse caseDescribes a real use case that is difficult or impossible, but does not propose a solution.Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Description
The following code will cause the compiler to go into an infinite function instantiation loop when compiling with zig build-exe bug.zig:
const std = @import("std");
fn comptimeFun(comptime s: []const u8) void {
@compileLog("comptimeFun with ", s);
// note: this next line causes the issue
comptimeFun(s ++ "");
// note: if we replace the line above with `comptimeFun(s)` then the infinite loop goes away
// note: the issue also manifests with: comptimeFun(s ++ "something")[0..s.len]);
}
pub fn main() void {
comptimeFun("foo");
}The problem here is that when Zig checks whether comptimeFun("foo") has already been instantiated, it's not seeing that slices with the same contents are equivalent. So even though comptimeFun is always called with the same comptime string "foo", it doesn't see them as equivalent so it just keeps instantiating them forever.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavioruse caseDescribes a real use case that is difficult or impossible, but does not propose a solution.Describes a real use case that is difficult or impossible, but does not propose a solution.