-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Reproduce the issue with these 2 files:
main.zig:
pub const foo = true;
usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};
usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};
pub fn main() void { }lib.zig:
pub const root_foo = @import("root").foo;./main.zig:4:38: error: dependency loop detected
usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};
^
./lib.zig:1:37: note: referenced here
pub const root_foo = @import("root").foo;
^
./main.zig:3:38: note: referenced here
usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};
^
/home/marler8997/zig/0.8.0-dev.1120+300ebbd56/files/lib/std/builtin.zig:669:73: note: referenced here
pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_panic;
What makes the dependency loop go away?
- the error goes away if you comment out one of the
usingnamespacelines inmain.zig
usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};
//usingnamespace if (@import("lib.zig").root_foo) struct {} else struct {};- the error goes away if
@import("lib.zig")is aliased and reused:
const lib = @import("lib.zig");
usingnamespace if (lib.root_foo) struct {} else struct {};
usingnamespace if (lib.root_foo) struct {} else struct {};- the error goes away if
lib.zigis removed and replaced with a struct:
const lib = struct { pub const root_foo = @import("root").foo; };
usingnamespace if (lib.root_foo) struct {} else struct {};
usingnamespace if (lib.root_foo) struct {} else struct {};Use Case
This error was found when trying to use a root variable UNICODE to select different win32 symbol aliases, like CreateFile is set to CreateFileA or CreateFileW based on @import("root").UNICODE. The affected project is https://github.com/marlersoft/zigwin32
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.