Skip to content

Commit

Permalink
Fixed glob uses starting with non-explicit dep crates. (#7011)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Jan 7, 2025
1 parent 7f60dfe commit 445314d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
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

0 comments on commit 445314d

Please sign in to comment.