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

Don't report inference diagnostics if there are other diagnostics. #5930

Merged
merged 1 commit into from
Jul 2, 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
10 changes: 0 additions & 10 deletions crates/cairo-lang-semantic/src/diagnostic_test_data/tests
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ error: Function not found.
1 + foo()
^*^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:3:1
1 + foo()
^*******^

//! > ==========================================================================

//! > Test function lookup
Expand Down Expand Up @@ -758,8 +753,3 @@ error: Are you missing a `::`?.
--> lib.cairo:4:18
let _fail = bar<felt252>(1);
^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:4:15
let _fail = bar<felt252>(1);
^*************^
14 changes: 12 additions & 2 deletions crates/cairo-lang-semantic/src/expr/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,9 +1032,19 @@ impl<'db> Inference<'db> {
.consumed_error
.expect("consumed_error is not set although error_status is Err(Consumed)"),
InferenceErrorStatus::Pending => {
let diag_added = mem::take(&mut self.error)
let diag_added = match mem::take(&mut self.error)
.expect("error is not set although error_status is Err(Pending)")
.report(diagnostics, stable_ptr);
{
InferenceError::TypeNotInferred(_) if diagnostics.error_count > 0 => {
// If we have other diagnostics, there is no need to TypeNotInferred.

// Note that `diagnostics` is not empty, so it is safe to return
// 'DiagnosticAdded' here.
skip_diagnostic()
}
diag => diag.report(diagnostics, stable_ptr),
};

self.error_status = Err(InferenceErrorStatus::Consumed);
self.consumed_error = Some(diag_added);
diag_added
Expand Down
5 changes: 0 additions & 5 deletions crates/cairo-lang-semantic/src/expr/test_data/if
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ error: Identifier not found.
return y == 9;
^

error: Type annotations needed. Failed to infer ?1.
--> lib.cairo:7:16
return y == 9;
^****^

//! > ==========================================================================

//! > if_let logical operators.
Expand Down
30 changes: 0 additions & 30 deletions crates/cairo-lang-semantic/src/expr/test_data/inline_macros
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?2.
--> lib.cairo:21:5
write!(f, "{non_existing}").unwrap();
^*************************^

//! > ==========================================================================

//! > Test bad writeln! macros
Expand Down Expand Up @@ -488,11 +483,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?2.
--> lib.cairo:21:5
writeln!(f, "{non_existing}").unwrap();
^***************************^

//! > ==========================================================================

//! > Test bad format! macros
Expand Down Expand Up @@ -606,11 +596,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?5.
--> lib.cairo:14:5
format!("{non_existing}");
^***********************^

//! > ==========================================================================

//! > Test bad print! macros
Expand Down Expand Up @@ -724,11 +709,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?5.
--> lib.cairo:14:5
print!("{non_existing}");
^**********************^

//! > ==========================================================================

//! > Test bad println! macros
Expand Down Expand Up @@ -842,11 +822,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?5.
--> lib.cairo:14:5
println!("{non_existing}");
^************************^

//! > ==========================================================================

//! > Test bad panic! macros
Expand Down Expand Up @@ -937,11 +912,6 @@ warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
let ba: ByteArray = "hello";
^^

error: Type annotations needed. Failed to infer ?4.
--> lib.cairo:14:5
panic!("{non_existing}");
^**********************^

//! > ==========================================================================

//! > Test unknown macro
Expand Down
10 changes: 0 additions & 10 deletions crates/cairo-lang-semantic/src/items/tests/early_conform
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,6 @@ Candidate `MyInto::my_into` inference failed with: Trait has no implementation i
let _ = MyType {} + 3_u16.my_into();
^*****^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:14:13
let _ = MyType {} + 3_u16.my_into();
^*************************^

//! > ==========================================================================

//! > Early conform of RHS of an assignment.
Expand Down Expand Up @@ -1137,11 +1132,6 @@ Candidate `MyInto::my_into` inference failed with: Trait has no implementation i
let _: bool = @(MyType {}) != @(3_u16.my_into());
^*****^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:15:19
let _: bool = MyType {} == 3_u16.my_into();
^**************************^

//! > ==========================================================================

//! > Early conform of an error propagation expression of an option.
Expand Down
5 changes: 0 additions & 5 deletions crates/cairo-lang-semantic/src/items/tests/trait_type
Original file line number Diff line number Diff line change
Expand Up @@ -2189,11 +2189,6 @@ error: Type annotations needed. Failed to infer ?0.
x.t
^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:6:18
let x = Trt::foo();
^*^

//! > ==========================================================================

//! > Using self calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,6 @@ error: Type not found.
#[starknet::contract]
^*******************^

error: Type annotations needed. Failed to infer ?2.
--> lib.cairo:1:1
#[starknet::contract]
^*******************^

error: Variable not dropped.
--> lib.cairo:6:40
fn foo<T>(ref self: ContractState, x: T) {}
Expand Down Expand Up @@ -7929,11 +7924,6 @@ error: Plugin diagnostic: The first argument of `get_dep_component_mut` macro mu
get_dep_component_mut!(ref mut self, Comp1).foo1();
^**^

error: Type annotations needed. Failed to infer ?2.
--> lib.cairo:51:49
get_dep_component_mut!(Comp1, self).foo1();
^**^

//! > generated_cairo_code
lib.cairo:

Expand Down