From 0759c7a43abd8fe8544ad0fce9ceedc1e56eab5d Mon Sep 17 00:00:00 2001 From: TomerC-StarkWare <167065153+Tomer-StarkWare@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:02:07 +0200 Subject: [PATCH] Use Star Edition filter (#6742) --- crates/cairo-lang-semantic/src/diagnostic.rs | 5 +++ .../src/diagnostic_test_data/tests | 45 +++++++++++++++++++ crates/cairo-lang-semantic/src/items/us.rs | 5 +++ 3 files changed, 55 insertions(+) diff --git a/crates/cairo-lang-semantic/src/diagnostic.rs b/crates/cairo-lang-semantic/src/diagnostic.rs index ab533f62266..3e6eb56328e 100644 --- a/crates/cairo-lang-semantic/src/diagnostic.rs +++ b/crates/cairo-lang-semantic/src/diagnostic.rs @@ -12,6 +12,7 @@ use cairo_lang_diagnostics::{ DiagnosticAdded, DiagnosticEntry, DiagnosticLocation, DiagnosticsBuilder, ErrorCode, Severity, error_code, }; +use cairo_lang_filesystem::db::Edition; use cairo_lang_syntax as syntax; use itertools::Itertools; use smol_str::SmolStr; @@ -534,6 +535,9 @@ impl DiagnosticEntry for SemanticDiagnostic { SemanticDiagnosticKind::UseStarEmptyPath => { "`*` in `use` items is not allowed for empty path.".into() } + SemanticDiagnosticKind::GlobalUsesNotSupportedInEdition(edition) => { + format!("Global `use` item is not supported in `{edition:?}` edition.") + } SemanticDiagnosticKind::TraitInTraitMustBeExplicit => { "In a trait, paths of the same trait must be fully explicit. Either use `Self` if \ this is the intention, or explicitly specify all the generic arguments." @@ -1166,6 +1170,7 @@ pub enum SemanticDiagnosticKind { PathNotFound(NotFoundItemType), AmbiguousPath(Vec), UseStarEmptyPath, + GlobalUsesNotSupportedInEdition(Edition), TraitInTraitMustBeExplicit, ImplInImplMustBeExplicit, TraitItemForbiddenInTheTrait, diff --git a/crates/cairo-lang-semantic/src/diagnostic_test_data/tests b/crates/cairo-lang-semantic/src/diagnostic_test_data/tests index e4a2c104281..831b31b2298 100644 --- a/crates/cairo-lang-semantic/src/diagnostic_test_data/tests +++ b/crates/cairo-lang-semantic/src/diagnostic_test_data/tests @@ -875,6 +875,9 @@ error: Are you missing a `::`?. //! > test_runner_name test_expr_diagnostics(expect_diagnostics: true) +//! > crate_settings +edition = "2024_07" + //! > module_code const NOT_MODULE: u8 = 2; pub mod a { @@ -901,6 +904,9 @@ error: Expected module, found constant. //! > test_runner_name test_expr_diagnostics(expect_diagnostics: true) +//! > crate_settings +edition = "2024_07" + //! > module_code pub mod a { pub const AMBIGUOUS: u8 = 1; @@ -933,6 +939,9 @@ AMBIGUOUS //! > test_runner_name test_expr_diagnostics(expect_diagnostics: true) +//! > crate_settings +edition = "2024_07" + //! > module_code use undefined_item::*; @@ -956,6 +965,9 @@ use undefined_item::*; //! > test_runner_name test_expr_diagnostics(expect_diagnostics: true) +//! > crate_settings +edition = "2024_07" + //! > module_code mod a { use super::*; @@ -982,6 +994,9 @@ error: Cycle detected while resolving 'use' items. //! > test_runner_name test_expr_diagnostics(expect_diagnostics: true) +//! > crate_settings +edition = "2024_07" + //! > module_code use *; @@ -1228,3 +1243,33 @@ error: Item `test::a::b` is not visible in this context. --> lib.cairo:9:34 pub use super::super::a::b::*; ^ + +//! > ========================================================================== + +//! > Testing use star not supported in edition + +//! > test_runner_name +test_expr_diagnostics(expect_diagnostics: true) + +//! > crate_settings +edition = "2023_01" + +//! > module_code +mod a { + pub const C: u8 = 1; +} + +use a::*; + +//! > function_body + +//! > expr_code +{} + +//! > expected_semantics + +//! > expected_diagnostics +error: Global `use` item is not supported in `V2023_01` edition. + --> lib.cairo:5:8 +use a::*; + ^ diff --git a/crates/cairo-lang-semantic/src/items/us.rs b/crates/cairo-lang-semantic/src/items/us.rs index c235d652e27..5ff61e9db58 100644 --- a/crates/cairo-lang-semantic/src/items/us.rs +++ b/crates/cairo-lang-semantic/src/items/us.rs @@ -180,6 +180,11 @@ pub fn priv_global_use_semantic_data( let inference_id = InferenceId::GlobalUseStar(global_use_id); let star_ast = ast::UsePath::Star(db.module_global_use_by_id(global_use_id)?.to_maybe()?); let mut resolver = Resolver::new(db, module_file_id, inference_id); + let edition = resolver.settings.edition; + if edition.ignore_visibility() { + // We block support for global use where visibility is ignored. + diagnostics.report(&star_ast, GlobalUsesNotSupportedInEdition(edition)); + } let item = star_ast.get_item(db.upcast()); let segments = get_use_path_segments(db.upcast(), star_ast.clone())?;