Skip to content

Commit b206af6

Browse files
ilyalesokhin-starkwareorizi
authored andcommitted
Fix error handling in assign_local_impl. (#8206)
1 parent 8578e23 commit b206af6

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

crates/cairo-lang-semantic/src/expr/inference.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'db> Inference<'db> {
797797
let impl_ty = self
798798
.db
799799
.impl_type_concrete_implized(ImplTypeId::new(impl_id, trait_type_id, self.db))
800-
.map_err(|_| ErrorSet)?;
800+
.map_err(|diag_added| self.set_error(InferenceError::Reported(diag_added)))?;
801801
if let Err(err_set) = self.conform_ty(ty, impl_ty) {
802802
// Override the error with ImplTypeMismatch.
803803
let ty0 = self.rewrite(ty).no_err();
@@ -809,24 +809,22 @@ impl<'db> Inference<'db> {
809809
}
810810
}
811811
for (trait_constant, constant_id) in mappings.constants {
812-
self.conform_const(
813-
constant_id,
814-
self.db
815-
.impl_constant_concrete_implized_value(ImplConstantId::new(
816-
impl_id,
817-
trait_constant,
818-
self.db,
819-
))
820-
.map_err(|_| ErrorSet)?,
821-
)?;
812+
let concrete_impl_constant = self
813+
.db
814+
.impl_constant_concrete_implized_value(ImplConstantId::new(
815+
impl_id,
816+
trait_constant,
817+
self.db,
818+
))
819+
.map_err(|diag_added| self.set_error(InferenceError::Reported(diag_added)))?;
820+
self.conform_const(constant_id, concrete_impl_constant)?;
822821
}
823822
for (trait_impl, inner_impl_id) in mappings.impls {
824-
self.conform_impl(
825-
inner_impl_id,
826-
self.db
827-
.impl_impl_concrete_implized(ImplImplId::new(impl_id, trait_impl, self.db))
828-
.map_err(|_| ErrorSet)?,
829-
)?;
823+
let concrete_impl_impl = self
824+
.db
825+
.impl_impl_concrete_implized(ImplImplId::new(impl_id, trait_impl, self.db))
826+
.map_err(|diag_added| self.set_error(InferenceError::Reported(diag_added)))?;
827+
self.conform_impl(inner_impl_id, concrete_impl_impl)?;
830828
}
831829
}
832830
Ok(impl_id)

crates/cairo-lang-semantic/src/expr/test_data/inference

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,3 +755,35 @@ error: Type annotations needed. Failed to infer ?0.
755755
--> lib.cairo:1:13
756756
fn foo() -> Option {
757757
^^^^^^
758+
759+
//! > ==========================================================================
760+
761+
//! > Use of an impl with and inferred and missing trait type.
762+
763+
//! > test_runner_name
764+
test_function_diagnostics(expect_diagnostics: true)
765+
766+
//! > function
767+
fn foo() {
768+
MyTrait::f();
769+
}
770+
771+
//! > function_name
772+
foo
773+
774+
//! > module_code
775+
trait MyTrait {
776+
type ty;
777+
fn f() -> Self::ty;
778+
}
779+
impl MyImpl of MyTrait {
780+
fn f() -> u32 {
781+
5_u32
782+
}
783+
}
784+
785+
//! > expected_diagnostics
786+
error[E0004]: Not all trait items are implemented. Missing: 'ty'.
787+
--> lib.cairo:5:6
788+
impl MyImpl of MyTrait {
789+
^^^^^^

0 commit comments

Comments
 (0)