diff --git a/crates/cairo-lang-lowering/src/db.rs b/crates/cairo-lang-lowering/src/db.rs index d62fd71bdec..e9ac7f4aa6e 100644 --- a/crates/cairo-lang-lowering/src/db.rs +++ b/crates/cairo-lang-lowering/src/db.rs @@ -732,7 +732,16 @@ fn module_lowering_diagnostics( ModuleItemId::Enum(_) => {} ModuleItemId::TypeAlias(_) => {} ModuleItemId::ImplAlias(_) => {} - ModuleItemId::Trait(_) => {} + ModuleItemId::Trait(trait_id) => { + for trait_func in db.trait_functions(*trait_id)?.values() { + if matches!(db.trait_function_body(*trait_func), Ok(Some(_))) { + let function_id = defs::ids::FunctionWithBodyId::Trait(*trait_func); + diagnostics.extend( + db.semantic_function_with_body_lowering_diagnostics(function_id)?, + ); + } + } + } ModuleItemId::Impl(impl_def_id) => { for impl_func in db.impl_functions(*impl_def_id)?.values() { let function_id = defs::ids::FunctionWithBodyId::Impl(*impl_func); diff --git a/crates/cairo-lang-semantic/src/items/trt.rs b/crates/cairo-lang-semantic/src/items/trt.rs index bb99e56d40a..de5b07930c5 100644 --- a/crates/cairo-lang-semantic/src/items/trt.rs +++ b/crates/cairo-lang-semantic/src/items/trt.rs @@ -1355,7 +1355,7 @@ pub fn priv_trait_function_body_data( // Compute declaration semantic. let trait_function_declaration_data = db.priv_trait_function_declaration_data(trait_function_id)?; - let parent_resolver_data = db.trait_resolver_data(trait_id)?; + let parent_resolver_data = trait_function_declaration_data.resolver_data; let inference_id = InferenceId::LookupItemDefinition(LookupItemId::TraitItem( TraitItemId::Function(trait_function_id), )); diff --git a/tests/bug_samples/issue7031.cairo b/tests/bug_samples/issue7031.cairo new file mode 100644 index 00000000000..e6df5cdc41d --- /dev/null +++ b/tests/bug_samples/issue7031.cairo @@ -0,0 +1,25 @@ +pub trait IteratorEx, +Destruct, +Drop> { + fn advance_by( + ref self: T, n: usize, + ) -> Result< + (), NonZero, + > { + let mut res = Result::Ok(()); + for i in 0..n { + if self.next().is_none() { + res = Result::Err((n - i).try_into().unwrap()); + break; + } + }; + res + } +} +impl ItratorExImpl, +Destruct, +Drop> of IteratorEx {} + +#[test] +fn test_advance_by() { + let mut iter = array![1_u8, 2, 3, 4].into_iter(); + assert_eq!(iter.advance_by(2), Result::Ok(())); + assert_eq!(iter.next(), Option::Some(3)); + assert_eq!(iter.advance_by(0), Result::Ok(())); +} diff --git a/tests/bug_samples/issue7038.cairo b/tests/bug_samples/issue7038.cairo new file mode 100644 index 00000000000..1693a0786f1 --- /dev/null +++ b/tests/bug_samples/issue7038.cairo @@ -0,0 +1,5 @@ +trait DefaultTraitImpl { + fn call, impl func: core::ops::FnOnce[Output: T], +Drop>(f: F) { + f(); + } +} diff --git a/tests/bug_samples/lib.cairo b/tests/bug_samples/lib.cairo index 2d6b0c1a301..42ca1448fb6 100644 --- a/tests/bug_samples/lib.cairo +++ b/tests/bug_samples/lib.cairo @@ -53,6 +53,8 @@ mod issue6623; mod issue6755; mod issue6920; mod issue6968; +mod issue7031; +mod issue7038; mod loop_break_in_match; mod loop_only_change; mod partial_param_local;