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

Made use * of non pub items not affect the compilation. #6919

Merged
merged 1 commit into from
Dec 24, 2024
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
16 changes: 15 additions & 1 deletion corelib/src/test/language_features/glob_use_test.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
pub mod a {
mod a {
pub const NON_SHADOWED: felt252 = 'non_shadowed';
pub const SHADOWED: felt252 = 'original_shadowed';
pub const PUBLISHED_ONCE: felt252 = 'published_once';
}

mod b {
const PUBLISHED_ONCE: felt252 = 'ignored';
#[allow(unused_imports)]
use core::array::Span;
}

pub const SHADOWED: felt252 = 'new_shadowed';
use a::*;
use b::*;

#[test]
fn test_use_star_shadowing() {
assert_eq!(NON_SHADOWED, 'non_shadowed');
assert_eq!(SHADOWED, 'new_shadowed');
}

#[test]
fn test_use_star_non_pub() {
assert_eq!(PUBLISHED_ONCE, 'published_once');
let _x: Span<felt252> = [].span();
}
50 changes: 29 additions & 21 deletions crates/cairo-lang-semantic/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,40 +1129,44 @@ impl<'db> Resolver<'db> {
let mut item_info = None;
let mut module_items_found: OrderedHashSet<ModuleItemId> = OrderedHashSet::default();
let imported_modules = self.db.priv_module_use_star_modules(module_id);
let mut containing_modules = vec![];
let mut is_accessible = false;
for (star_module_id, item_module_id) in &imported_modules.accessible {
if let Some(inner_item_info) =
self.resolve_item_in_imported_module(*item_module_id, identifier)
{
item_info = Some(inner_item_info.clone());
is_accessible |=
self.is_item_visible(*item_module_id, &inner_item_info, *star_module_id)
&& self.is_item_feature_usable(&inner_item_info);
module_items_found.insert(inner_item_info.item_id);
}
}
for star_module_id in &imported_modules.all {
if let Some(inner_item_info) =
self.resolve_item_in_imported_module(*star_module_id, identifier)
{
item_info = Some(inner_item_info.clone());
module_items_found.insert(inner_item_info.item_id);
containing_modules.push(*star_module_id);
if self.is_item_visible(*item_module_id, &inner_item_info, *star_module_id)
&& self.is_item_feature_usable(&inner_item_info)
{
item_info = Some(inner_item_info.clone());
module_items_found.insert(inner_item_info.item_id);
}
}
}
if module_items_found.len() > 1 {
return UseStarResult::AmbiguousPath(module_items_found.iter().cloned().collect());
}
match item_info {
Some(item_info) => {
if is_accessible {
UseStarResult::UniquePathFound(item_info)
Some(item_info) => UseStarResult::UniquePathFound(item_info),
None => {
let mut containing_modules = vec![];
for star_module_id in &imported_modules.all {
if let Some(inner_item_info) =
self.resolve_item_in_imported_module(*star_module_id, identifier)
{
item_info = Some(inner_item_info.clone());
module_items_found.insert(inner_item_info.item_id);
containing_modules.push(*star_module_id);
}
}
if let Some(item_info) = item_info {
if module_items_found.len() > 1 {
UseStarResult::AmbiguousPath(module_items_found.iter().cloned().collect())
} else {
UseStarResult::ItemNotVisible(item_info.item_id, containing_modules)
}
} else {
UseStarResult::ItemNotVisible(item_info.item_id, containing_modules)
UseStarResult::PathNotFound
}
}
None => UseStarResult::PathNotFound,
}
}

Expand Down Expand Up @@ -1305,6 +1309,10 @@ impl<'db> Resolver<'db> {
}
UseStarResult::PathNotFound => {}
UseStarResult::ItemNotVisible(module_item_id, containing_modules) => {
let prelude = self.prelude_submodule();
if let Ok(Some(_)) = self.db.module_item_by_name(prelude, ident) {
return ResolvedBase::Module(prelude);
}
return ResolvedBase::ItemNotVisible(module_item_id, containing_modules);
}
}
Expand Down
Loading