From 0de9de6fd2d0fcdb89dc1abdf58013a91a34b803 Mon Sep 17 00:00:00 2001 From: TomerStarkware Date: Thu, 25 Sep 2025 12:00:22 +0300 Subject: [PATCH] add diagnostic when use star causes cycles --- .../cairo-lang-semantic/src/items/tests/use_ | 71 +++++++++++++++++++ crates/cairo-lang-semantic/src/items/us.rs | 12 +++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/crates/cairo-lang-semantic/src/items/tests/use_ b/crates/cairo-lang-semantic/src/items/tests/use_ index 7f71f6a38f0..d00b7e6b1a9 100644 --- a/crates/cairo-lang-semantic/src/items/tests/use_ +++ b/crates/cairo-lang-semantic/src/items/tests/use_ @@ -178,3 +178,74 @@ error: `self` in `use` items is not allowed for empty path. --> lib.cairo:1:6 use {self, u8}; ^^^^ + +//! > ========================================================================== + +//! > Use star on a module that was imported with use star. + +//! > test_runner_name +test_function_diagnostics(expect_diagnostics: true) + +//! > function +fn foo() { + C::test(); +} + +//! > function_name +foo + +//! > module_code +mod A { + pub mod B { + pub mod C { + pub fn test() {} + } + } +} +use A::*; +use B::*; + +//! > expected_diagnostics +error[E0006]: Identifier not found. + --> lib.cairo:11:5 + C::test(); + ^ + +error: Global `use` item is not supported in `V2023_01` edition. + --> lib.cairo:8:8 +use A::*; + ^ + +error[E0006]: Identifier not found. + --> lib.cairo:9:5 +use B::*; + ^ + +//! > ========================================================================== + +//! > Use star on a non existing module. + +//! > test_runner_name +test_function_diagnostics(expect_diagnostics: true) + +//! > function +fn foo() { + C::test(); +} + +//! > function_name +foo + +//! > module_code +use B::*; + +//! > expected_diagnostics +error[E0006]: Identifier not found. + --> lib.cairo:3:5 + C::test(); + ^ + +error[E0006]: Identifier not found. + --> lib.cairo:1:5 +use B::*; + ^ diff --git a/crates/cairo-lang-semantic/src/items/us.rs b/crates/cairo-lang-semantic/src/items/us.rs index 66de073cedc..67c2602d510 100644 --- a/crates/cairo-lang-semantic/src/items/us.rs +++ b/crates/cairo-lang-semantic/src/items/us.rs @@ -374,7 +374,7 @@ pub struct ImportInfo<'db> { /// Returns the modules that are imported with `use *` and macro calls in the current module. /// Query implementation of [UseSemantic::module_imported_modules]. -#[salsa::tracked(returns(ref))] +#[salsa::tracked(returns(ref),cycle_result=module_imported_modules_cycle)] fn module_imported_modules<'db>( db: &'db dyn Database, _tracked: Tracked, @@ -430,6 +430,16 @@ fn module_imported_modules<'db>( modules } +/// Cycle handling for [UseSemantic::module_imported_modules]. +fn module_imported_modules_cycle<'db>( + _db: &'db dyn Database, + _tracked: Tracked, + _module_id: ModuleId<'db>, +) -> ImportedModules<'db> { + Default::default() +} + + /// Trait for use-related semantic queries. pub trait UseSemantic<'db>: Database { /// Private query to compute data about a use.