Sitelet https://github.com/starkware-libs/cairo/commit/4f661acac4b4605d4bb89714aa9517a3b8059cfe
Skip to content

Commit 4f661ac

Browse files
committed
fix(semantic): report every invalid associated-item constraint, not just the first
While collecting a generic parameter's associated-item constraints, the `NonTraitTypeConstrained` arm did `return map`, abandoning the rest of the constraint list after the first bad one. So `+MyTrait<T>[Bogus1: u8, Bogus2: u16]` reported E2189 only for `Bogus1` and silently dropped `Bogus2`. Replace `return map` with `continue`, matching the sibling arm, so each invalid constraint is diagnosed. Adds an `expr/test_data/generics` golden (gated on the experimental `associated_item_constraints` feature) asserting both `Bogus1` and `Bogus2` are reported.
1 parent ad70feb commit 4f661ac

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎crates/cairo-lang-semantic/src/expr/test_data/generics‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,41 @@ error[E2038]: Generic parameter kind of impl function `FooImpl::bar` is incompat
754754
--> lib.cairo:5:12
755755
fn bar<+Drop<felt252>>(self: felt252) {}
756756
^^^^^^^^^^^^^^
757+
758+
//! > ==========================================================================
759+
760+
//! > Multiple invalid associated-item constraints are each reported (not just the first).
761+
762+
//! > test_runner_name
763+
test_function_diagnostics(expect_diagnostics: true)
764+
765+
//! > function_code
766+
fn foo() {}
767+
768+
//! > function_name
769+
foo
770+
771+
//! > module_code
772+
trait MyTrait<T> {
773+
type Real;
774+
}
775+
776+
fn bar<T, +MyTrait<T>[Bogus1: u8, Bogus2: u16]>() {}
777+
778+
//! > crate_settings
779+
edition = "2024_07"
780+
781+
[experimental_features]
782+
negative_impls = false
783+
associated_item_constraints = true
784+
785+
//! > expected_diagnostics
786+
error[E2189]: associated type `Bogus1` not found for `MyTrait`
787+
--> lib.cairo:5:23
788+
fn bar<T, +MyTrait<T>[Bogus1: u8, Bogus2: u16]>() {}
789+
^^^^^^^^^^
790+
791+
error[E2189]: associated type `Bogus2` not found for `MyTrait`
792+
--> lib.cairo:5:35
793+
fn bar<T, +MyTrait<T>[Bogus1: u8, Bogus2: u16]>() {}
794+
^^^^^^^^^^^

‎crates/cairo-lang-semantic/src/items/generics.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn impl_generic_param_semantic<'db>(
713713
concrete_trait_id,
714714
},
715715
);
716-
return map;
716+
continue;
717717
};
718718

719719
let concrete_trait_type_id =

0 commit comments

Comments
 (0)