Skip to content

Commit

Permalink
Use Star Edition filter (#6742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer-StarkWare authored Nov 26, 2024
1 parent 2568383 commit 0759c7a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/cairo-lang-semantic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -1166,6 +1170,7 @@ pub enum SemanticDiagnosticKind {
PathNotFound(NotFoundItemType),
AmbiguousPath(Vec<ModuleItemId>),
UseStarEmptyPath,
GlobalUsesNotSupportedInEdition(Edition),
TraitInTraitMustBeExplicit,
ImplInImplMustBeExplicit,
TraitItemForbiddenInTheTrait,
Expand Down
45 changes: 45 additions & 0 deletions crates/cairo-lang-semantic/src/diagnostic_test_data/tests
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -933,6 +939,9 @@ AMBIGUOUS
//! > test_runner_name
test_expr_diagnostics(expect_diagnostics: true)

//! > crate_settings
edition = "2024_07"

//! > module_code
use undefined_item::*;

Expand All @@ -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::*;
Expand All @@ -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 *;

Expand Down Expand Up @@ -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::*;
^
5 changes: 5 additions & 0 deletions crates/cairo-lang-semantic/src/items/us.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down

0 comments on commit 0759c7a

Please sign in to comment.