Skip to content

Commit

Permalink
fix missing implicit impls repoorting (#7139)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerStarkware authored Jan 26, 2025
1 parent e2ab0a5 commit 1fba177
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/cairo-lang-semantic/src/expr/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,8 @@ impl SemanticRewriter<ImplLongId, NoError> for Inference<'_> {
impl_impl_id_rewrite_result
}
ImplLongId::Concrete(_) => {
if let Ok(ty) = self.db.impl_impl_concrete_implized(*impl_impl_id) {
*value = self.rewrite(ty).no_err().lookup_intern(self.db);
if let Ok(imp) = self.db.impl_impl_concrete_implized(*impl_impl_id) {
*value = self.rewrite(imp).no_err().lookup_intern(self.db);
RewriteResult::Modified
} else {
impl_impl_id_rewrite_result
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-semantic/src/items/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,7 @@ pub fn priv_implicit_impl_impl_semantic_data(
let impl_lookup_context = resolver.impl_lookup_context();
let resolved_impl = concrete_trait_impl_concrete_trait.and_then(|concrete_trait_id| {
let imp = resolver.inference().new_impl_var(concrete_trait_id, None, impl_lookup_context);
if let Err((err_set, _)) = resolver.inference().finalize_without_reporting() {
resolver.inference().finalize_without_reporting().map_err(|(err_set, _)| {
diagnostics.report(
impl_def_id.stable_ptr(db.upcast()).untyped(),
ImplicitImplNotInferred { trait_impl_id, concrete_trait_id },
Expand All @@ -2796,8 +2796,8 @@ pub fn priv_implicit_impl_impl_semantic_data(
err_set,
&mut diagnostics,
impl_def_id.stable_ptr(db.upcast()).untyped(),
);
};
)
})?;
resolver.inference().rewrite(imp).map_err(|_| skip_diagnostic())
});

Expand Down
87 changes: 87 additions & 0 deletions crates/cairo-lang-semantic/src/items/tests/trait_impl
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,14 @@ error: Trait has no implementation in context: test::OtherTrait.
impl MyImpl of MyTrait {}
^^^^^^^^^^^^^^^^^^^^^^^^^

error: Trait has no implementation in context: test::MyTrait.
--> lib.cairo:8:10-10:1
fn foo() {
__________^
| MyImpl::I::f()
| }
|_^

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

//! > Inferring missing Impl Impl from context.
Expand Down Expand Up @@ -1280,3 +1288,82 @@ mod my_mod {
}

//! > expected_diagnostics

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

//! > implicit impl is not found when implizing generic impl argument.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function
fn foo() {
1_u64.foo(1_u32);
}

//! > function_name
foo

//! > module_code
trait Outer<R> {
impl InnerImpl: Inner<R>;
type Item;
fn into(self: R) -> Self::Item;
}
trait Inner<R> {
type Item;
fn foo<
U,
impl OuterU: Outer<U>,
+core::metaprogramming::TypeEqual<Self::Item, OuterU::InnerImpl::Item>,
+Destruct<R>,
>(
self: R, u: U,
) -> (R, U) {
(self, u.into())
}
}

impl InnerU64 of Inner<u64> {
type Item = u32;
}

impl OuterU32 of Outer<u32> {
type Item = u64;
fn into(self: u32) -> u64 {
self.into()
}
}

//! > expected_diagnostics
error: Ambiguous method call. More than one applicable trait function with a suitable self type was found: core::traits::Into::into and test::Outer::into. Consider adding type annotations or explicitly refer to the impl function.
--> lib.cairo:16:18
(self, u.into())
^^^^

error: Ambiguous method call. More than one applicable trait function with a suitable self type was found: core::traits::Into::into and test::Outer::into. Consider adding type annotations or explicitly refer to the impl function.
--> lib.cairo:27:14
self.into()
^^^^

error: Cannot infer implicit impl `InnerImpl.`
Could not find implementation of trait `test::Inner::<core::integer::u32>`
--> lib.cairo:24:1-29:1
impl OuterU32 of Outer<u32> {
_^
| ...
| }
|_^

error: Trait has no implementation in context: test::Inner::<core::integer::u32>.
--> lib.cairo:24:1-29:1
impl OuterU32 of Outer<u32> {
_^
| ...
| }
|_^

error: Trait has no implementation in context: core::metaprogramming::TypeEqual::<core::integer::u32, OuterU32::test::Inner::<core::integer::u32>::Item>.
--> lib.cairo:31:11
1_u64.foo(1_u32);
^^^

0 comments on commit 1fba177

Please sign in to comment.