Skip to content

Commit 41dabb0

Browse files
piotmag769orizi
authored andcommitted
Warning instead of error on unsupported allow attributes (#7442)
1 parent 03352b2 commit 41dabb0

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

crates/cairo-lang-semantic/src/diagnostic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,8 @@ impl DiagnosticEntry for SemanticDiagnostic {
10551055
| SemanticDiagnosticKind::UnusedImport { .. }
10561056
| SemanticDiagnosticKind::CallingShadowedFunction { .. }
10571057
| SemanticDiagnosticKind::UnusedConstant
1058-
| SemanticDiagnosticKind::UnusedUse => Severity::Warning,
1058+
| SemanticDiagnosticKind::UnusedUse
1059+
| SemanticDiagnosticKind::UnsupportedAllowAttrArguments => Severity::Warning,
10591060
SemanticDiagnosticKind::PluginDiagnostic(diag) => diag.severity,
10601061
_ => Severity::Error,
10611062
}

crates/cairo-lang-semantic/src/diagnostic_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cairo_lang_test_utils::test_file_test!(
2727
diagnostics,
2828
"src/diagnostic_test_data",
2929
{
30+
allow: "allow",
3031
allow_attr: "allow_attr",
3132
deref: "deref",
3233
tests: "tests",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! > Test allow_attr attribute
2+
3+
//! > test_runner_name
4+
test_expr_diagnostics(expect_diagnostics: true)
5+
6+
//! > expr_code
7+
{}
8+
9+
//! > module_code
10+
#[allow(unused_imports)] // Valid allow arg.
11+
mod some {
12+
use core::ArrayTrait;
13+
}
14+
15+
#[allow(invalid_lint)] // Invalid allow arg.
16+
fn func() {}
17+
18+
//! > generated_cairo_code
19+
20+
//! > function_body
21+
22+
//! > expected_diagnostics
23+
warning: `allow` attribute argument not supported.
24+
--> lib.cairo:6:8
25+
#[allow(invalid_lint)] // Invalid allow arg.
26+
^^^^^^^^^^^^^^

crates/cairo-lang-starknet/src/analyzer.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cairo_lang_semantic::types::get_impl_at_context;
1010
use cairo_lang_semantic::{
1111
ConcreteTraitId, ConcreteTraitLongId, ConcreteTypeId, GenericArgumentId, TypeId, TypeLongId,
1212
};
13-
use cairo_lang_syntax::attribute::consts::STARKNET_INTERFACE_ATTR;
13+
use cairo_lang_syntax::attribute::consts::{ALLOW_ATTR, STARKNET_INTERFACE_ATTR};
1414
use cairo_lang_syntax::node::helpers::QueryAttrs;
1515
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
1616
use cairo_lang_syntax::node::{Terminal, TypedStablePtr, TypedSyntaxNode};
@@ -130,7 +130,7 @@ impl AnalyzerPlugin for StorageAnalyzer {
130130
if let Ok(module_enums) = db.module_enums(module_id) {
131131
for (id, item) in module_enums.iter() {
132132
if has_derive(item, syntax_db, STORE_TRAIT).is_some()
133-
&& !item.has_attr_with_arg(syntax_db, "allow", ALLOW_NO_DEFAULT_VARIANT_ATTR)
133+
&& !item.has_attr_with_arg(syntax_db, ALLOW_ATTR, ALLOW_NO_DEFAULT_VARIANT_ATTR)
134134
{
135135
add_derive_store_enum_diags(db, *id, &mut diagnostics);
136136
}
@@ -160,9 +160,9 @@ fn analyze_storage_struct(
160160
return;
161161
};
162162
let allow_invalid_members =
163-
struct_id.has_attr_with_arg(db, "allow", ALLOW_INVALID_STORAGE_MEMBERS_ATTR) == Ok(true);
163+
struct_id.has_attr_with_arg(db, ALLOW_ATTR, ALLOW_INVALID_STORAGE_MEMBERS_ATTR) == Ok(true);
164164
let allow_collisions =
165-
struct_id.has_attr_with_arg(db, "allow", ALLOW_COLLIDING_PATHS_ATTR) == Ok(true);
165+
struct_id.has_attr_with_arg(db, ALLOW_ATTR, ALLOW_COLLIDING_PATHS_ATTR) == Ok(true);
166166

167167
let lookup_context = ImplLookupContext::new(
168168
struct_id.module_file_id(db.upcast()).0,
@@ -178,8 +178,11 @@ fn analyze_storage_struct(
178178
let member_type = member.ty.lookup_intern(db);
179179
let concrete_trait_id = concrete_valid_storage_trait(db, db.intern_type(member_type));
180180

181-
let member_allows_invalid =
182-
member_ast.has_attr_with_arg(db.upcast(), "allow", ALLOW_INVALID_STORAGE_MEMBERS_ATTR);
181+
let member_allows_invalid = member_ast.has_attr_with_arg(
182+
db.upcast(),
183+
ALLOW_ATTR,
184+
ALLOW_INVALID_STORAGE_MEMBERS_ATTR,
185+
);
183186

184187
if !(allow_invalid_members || member_allows_invalid) {
185188
let inference_result =
@@ -203,7 +206,7 @@ fn analyze_storage_struct(
203206

204207
// Check for storage path collisions.
205208
if allow_collisions
206-
|| member_ast.has_attr_with_arg(db.upcast(), "allow", ALLOW_COLLIDING_PATHS_ATTR)
209+
|| member_ast.has_attr_with_arg(db.upcast(), ALLOW_ATTR, ALLOW_COLLIDING_PATHS_ATTR)
207210
{
208211
continue;
209212
}

0 commit comments

Comments
 (0)