diff --git a/crates/flux-fhir-analysis/locales/en-US.ftl b/crates/flux-fhir-analysis/locales/en-US.ftl index efcbb5a39d..0f3b941bcc 100644 --- a/crates/flux-fhir-analysis/locales/en-US.ftl +++ b/crates/flux-fhir-analysis/locales/en-US.ftl @@ -228,7 +228,7 @@ fhir_analysis_generics_on_type_parameter = .label = found generics on sort type parameter fhir_analysis_generics_on_self_alias = - type alias `Self` expect not generics but found {$found} + type alias Self expects no generics but found {$found} .label = found generics on type `Self` fhir_analysis_generics_on_opaque_sort = diff --git a/crates/flux-fhir-analysis/src/conv/mod.rs b/crates/flux-fhir-analysis/src/conv/mod.rs index 45e2b8a99f..847b4e607d 100644 --- a/crates/flux-fhir-analysis/src/conv/mod.rs +++ b/crates/flux-fhir-analysis/src/conv/mod.rs @@ -1990,10 +1990,19 @@ fn conv_sort_path( } return Ok(rty::Sort::Param(def_id_to_param_ty(genv, def_id))); } - fhir::SortRes::SelfParam { .. } => return Ok(rty::Sort::Param(rty::SELF_PARAM_TY)), + fhir::SortRes::SelfParam { .. } => { + if !path.args.is_empty() { + let err = errors::GenericsOnSelf::new( + path.segments.last().unwrap().span, + path.args.len(), + ); + return Err(genv.sess().emit_err(err))?; + } + return Ok(rty::Sort::Param(rty::SELF_PARAM_TY)); + } fhir::SortRes::SelfAlias { alias_to } => { if !path.args.is_empty() { - let err = errors::GenericsOnSelfAlias::new( + let err = errors::GenericsOnSelf::new( path.segments.last().unwrap().span, path.args.len(), ); @@ -2326,14 +2335,14 @@ mod errors { #[derive(Diagnostic)] #[diag(fhir_analysis_generics_on_type_parameter, code = E0999)] - pub(super) struct GenericsOnSelfAlias { + pub(super) struct GenericsOnSelf { #[primary_span] #[label] span: Span, found: usize, } - impl GenericsOnSelfAlias { + impl GenericsOnSelf { pub(super) fn new(span: Span, found: usize) -> Self { Self { span, found } } diff --git a/tests/tests/neg/error_messages/conv/mismatched_generics.rs b/tests/tests/neg/error_messages/conv/mismatched_generics.rs new file mode 100644 index 0000000000..9f64678bac --- /dev/null +++ b/tests/tests/neg/error_messages/conv/mismatched_generics.rs @@ -0,0 +1,54 @@ +use flux_rs::*; + +#[refined_by(n: int)] +struct S { + #[field(i32[n])] + f: i32, +} + +defs! { + fn foo(s: S) -> int { //~ Error sorts associated with this struct should have no generic arguments but 1 generic argument supplied + s.n + } + + fn foo2(x: int) -> int { //~ Error primitive sort int expects no generics but found 1 + 1 + } + + fn foo3(x: Map) -> int { //~ Error primitive sort Map expects exactly 2 generic arguments but found 1 + 1 + } + + fn foo4(x: Map) -> int { //~ Error primitive sort Map expects exactly 2 generic arguments but found 0 + 1 + } + + fn foo5(x: Set) -> int { //~ Error primitive sort Set expects exactly one generic argument but found 2 + 1 + } + + fn foo6(x: real) -> real { //~ Error primitive sort real expects no generics but found 1 + 1 + } + + fn foo7(x: bool) -> real { //~ Error primitive sort bool expects no generics but found 1 + 1 + } +} + +#[flux::refined_by(f: T)] //~ Error type parameter expects no generics but found 1 +struct X { + #[flux::field(T[f])] + f: T +} + +#[flux::assoc(fn foo(x: Self) -> int)] //~ Error type parameter expects no generics but found 1 +trait MyTrait {} + +flux_rs::defs! { + opaque sort MyOpaqueSort; +} + +#[flux_rs::opaque] +#[flux_rs::refined_by(f: MyOpaqueSort)] //~ Error type parameter expects no generics but found 1 +struct Y {}