Skip to content

@import is case-sensitive on case-insensitive filesystems, causing modules to instantiate multiple times #19517

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

Closed
Jarred-Sumner opened this issue Apr 3, 2024 · 3 comments

Comments

@Jarred-Sumner
Copy link
Contributor

Zig Version

0.12.0-dev.1830+779b8e259

Steps to Reproduce and Observed Behavior

  1. Paste this code in repro.zig
pub const Bar = struct {};
test {
    const Bar2 = @import("repro.zig").Bar;
    const Bar3 = @import("Repro.zig").Bar;
    try @import("std").testing.expectEqual(Bar3, Bar2);
    try @import("std").testing.expectEqual(Bar, Bar2);
}
  1. Run zig test repro.zig
  2. Receive output:
Test [1/2] test_0... expected type Repro.Bar, found type repro.Bar
Test [1/2] test_0... FAIL (TestExpectedEqual)
/Users/jarred/zig/0.12.0-dev.1830+779b8e259/files/lib/std/testing.zig:72:17: 0x100d90783 in expectEqual__anon_913 (test)
                return error.TestExpectedEqual;
                ^
/private/tmp/esm-test/repro.zig:5:5: 0x100d90923 in test_0 (test)
    try @import("std").testing.expectEqual(Bar3, Bar2);
    ^
Test [2/2] test_0... expected type Repro.Bar, found type repro.Bar
Test [2/2] test_0... FAIL (TestExpectedEqual)
/Users/jarred/zig/0.12.0-dev.1830+779b8e259/files/lib/std/testing.zig:72:17: 0x100d90783 in expectEqual__anon_913 (test)
                return error.TestExpectedEqual;
                ^
/private/tmp/esm-test/Repro.zig:5:5: 0x100d99b5f in test_0 (test)
    try @import("std").testing.expectEqual(Bar3, Bar2);
    ^
0 passed; 0 skipped; 2 failed.
error: the following test command failed with exit code 1:
/Users/jarred/.cache/zig/o/671cd7af27c0982718ac963922ef6968/test

Expected Behavior

Test should pass

This issue is similar to #9786, but not a duplicate because this reproduces on macOS as well as Windows.

On macOS, the default filesystem is case-insensitive (APFS). HFS+ can be case sensitive but it also defaults to case-insensitive. On Windows, the rules are more complicated.

@Jarred-Sumner Jarred-Sumner added the bug Observed behavior contradicts documented or intended behavior label Apr 3, 2024
@Jarred-Sumner Jarred-Sumner changed the title @import is case-sensitive on case-insensitive filesystems, causing modules to instantiate duplicate times @import is case-sensitive on case-insensitive filesystems, causing modules to instantiate multiple times Apr 3, 2024
@Cloudef
Copy link
Contributor

Cloudef commented Apr 3, 2024

This sounds like the imports should be normalized so there can't be foo.zig and Foo.zig

@ifreund
Copy link
Member

ifreund commented Apr 3, 2024

Duplicate of #9786

@ifreund ifreund marked this as a duplicate of #9786 Apr 3, 2024
@ifreund ifreund closed this as completed Apr 3, 2024
@ifreund ifreund closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@ifreund ifreund removed the bug Observed behavior contradicts documented or intended behavior label Apr 3, 2024
@ifreund
Copy link
Member

ifreund commented Apr 3, 2024

It's mentioned in #9786 that this reproduces on other systems than windows, e.g. linux filesystems with case-folding enabled. I don't see any reason to have a second issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants