Skip to content

Importing a non-existing package should fail #13778

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
clebs opened this issue Dec 5, 2022 · 4 comments
Closed

Importing a non-existing package should fail #13778

clebs opened this issue Dec 5, 2022 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@clebs
Copy link
Contributor

clebs commented Dec 5, 2022

Zig Version

0.11.0-dev.231+476b94680

Steps to Reproduce and Observed Behavior

Compile an executable with this main.zig:

const std = @import("std");
const x = @import("blablabla"); // this package does not exist and is not added to build.zig

pub fn main() !void {
    std.debug.print("Somehow this compiles\n", .{});
}

Expected Behavior

The compilation fails as the package does not exist.

I noticed that this does fail when trying to do something with const x. If trying to use the package then the right error shows up:

error: no package named 'blablabla' available within package 'root'
const x = @import("blablabla");
                  ^~~~~~~~~~~

Maybe a solution to avoid this case is detecting unused imports.

@clebs clebs added the bug Observed behavior contradicts documented or intended behavior label Dec 5, 2022
@Vexu
Copy link
Member

Vexu commented Dec 5, 2022

This is Zig's lazy analysis working as designed, see #2529 for more discussion about this.

@Vexu Vexu closed this as completed Dec 5, 2022
@clebs
Copy link
Contributor Author

clebs commented Dec 5, 2022

Thanks for the info! I might be misunderstanding, but shouldn't this work according to this comment?
#7867 (comment)

@Vexu
Copy link
Member

Vexu commented Dec 5, 2022

"blablabla" is not a file, it's a package and AstGen cannot know if it exists or not.

@clebs
Copy link
Contributor Author

clebs commented Dec 5, 2022

I see, thanks for the clarification. I was confused because the code sample in that issue uses this statement:
const mylib = @import("nonexistent");. So I assumed by importing a file, both files and packages were meant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants