Skip to content
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

Fixed glob uses starting with non-explicit dep crates. #7011

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions crates/cairo-lang-semantic/src/expr/semantic_test_data/use
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,64 @@ FunctionCall(

//! > ==========================================================================

//! > Use glob path starting with `core::`.

//! > test_runner_name
test_expr_semantics(expect_diagnostics: false)

//! > crate_settings
edition = "2024_07"

//! > module_code
use core::starknet::*;

//! > function_body

//! > expr_code
{}

//! > expected_semantics
Block(
ExprBlock {
statements: [],
tail: None,
ty: (),
},
)

//! > expected_diagnostics

//! > ==========================================================================

//! > Use glob path starting with `starknet::`.

//! > test_runner_name
test_expr_semantics(expect_diagnostics: false)

//! > crate_settings
edition = "2024_07"

//! > module_code
use starknet::*;

//! > function_body

//! > expr_code
{}

//! > expected_semantics
Block(
ExprBlock {
statements: [],
tail: None,
ty: (),
},
)

//! > expected_diagnostics

//! > ==========================================================================

//! > Test using a variant with a generic type.

//! > test_runner_name
Expand Down
15 changes: 11 additions & 4 deletions crates/cairo-lang-semantic/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ mod item;
pub const SELF_TYPE_KW: &str = "Self";
pub const SUPER_KW: &str = "super";
pub const CRATE_KW: &str = "crate";
// Remove when this becomes an actual crate.
const STARKNET_CRATE_NAME: &str = "starknet";

/// Lookback maps for item resolving. Can be used to quickly check what is the semantic resolution
/// of any path segment.
Expand Down Expand Up @@ -1303,6 +1305,15 @@ impl<'db> Resolver<'db> {

return ResolvedBase::Crate(dep_crate_id);
}
// If the first segment is `core` - and it was not overridden by a dependency - using it.
if ident == CORELIB_CRATE_NAME {
return ResolvedBase::Crate(CrateId::core(self.db));
}
// TODO(orizi): Remove when `starknet` becomes a proper crate.
if ident == STARKNET_CRATE_NAME {
// Making sure we don't look for it in `*` modules, to prevent cycles.
return ResolvedBase::Module(self.prelude_submodule());
}
// If an item with this name is found in one of the 'use *' imports, use the module that
match self.resolve_path_using_use_star(module_id, identifier) {
UseStarResult::UniquePathFound(inner_module_item) => {
Expand All @@ -1323,10 +1334,6 @@ impl<'db> Resolver<'db> {
return ResolvedBase::ItemNotVisible(module_item_id, containing_modules);
}
}
// If the first segment is `core` - and it was not overridden by a dependency - using it.
if ident == CORELIB_CRATE_NAME {
return ResolvedBase::Crate(CrateId::core(self.db));
}
ResolvedBase::Module(self.prelude_submodule())
}

Expand Down
Loading