-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.The process of building from source via WebAssembly and the C backend.
Milestone
Description
This code fails to compile with the following error:
const std = @import("std");
fn Frog(comptime T: type) type {
return struct { fish: T };
}
const Bear = struct {
grizzle: Frog([]Bear),
};
pub fn main() !void {
const my_precious = Bear{ .grizzle = undefined };
std.debug.warn("{}", .{my_precious});
}
./src/main.zig:9:14: error: struct 'Bear' depends on itself
const Bear = struct {
^
./src/main.zig:10:19: note: referenced here
grizzle: Frog([]Bear),
^
./src/main.zig:10:18: note: referenced here
grizzle: Frog([]Bear),
^
./src/main.zig:15:29: note: referenced here
const my_precious = Bear{
^
/usr/lib/zig/std/start.zig:253:40: note: referenced here
const result = root.main() catch |err| {
^
However, a small change which should produce identical code allows it to compile
const std = @import("std");
fn Frog(comptime T: type) type {
return struct { fish: []T };
}
const Bear = struct {
grizzle: Frog(Bear),
};
pub fn main() !void {
const my_precious = Bear{ .grizzle = undefined };
std.debug.warn("{}", .{my_precious});
}
In the second example Instead of passing a slice type to Frog
, the struct returned by Frog
always contains a slice. The first example which fails to compile is valid code as only a pointer to Bear
is stored, not the struct itself, so it should be allowed to compile.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.The process of building from source via WebAssembly and the C backend.