Skip to content

Commit

Permalink
Add tests for mismatched sort generics in conv
Browse files Browse the repository at this point in the history
  • Loading branch information
vrindisbacher committed Nov 5, 2024
1 parent d036ff2 commit 8b96f46
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/flux-fhir-analysis/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
17 changes: 13 additions & 4 deletions crates/flux-fhir-analysis/src/conv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;

Check warning on line 1999 in crates/flux-fhir-analysis/src/conv/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement with `?` operator

warning: unneeded `return` statement with `?` operator --> crates/flux-fhir-analysis/src/conv/mod.rs:1999:17 | 1999 | return Err(genv.sess().emit_err(err))?; | ^^^^^^^ help: remove it | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return_with_question_mark
}
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(),
);
Expand Down Expand Up @@ -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 }
}
Expand Down
54 changes: 54 additions & 0 deletions tests/tests/neg/error_messages/conv/mismatched_generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use flux_rs::*;

#[refined_by(n: int)]
struct S {
#[field(i32[n])]
f: i32,
}

defs! {
fn foo(s: S<int>) -> int { //~ Error sorts associated with this struct should have no generic arguments but 1 generic argument supplied
s.n
}

fn foo2(x: int<bool>) -> int { //~ Error primitive sort int expects no generics but found 1
1
}

fn foo3(x: Map<int>) -> 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, int>) -> int { //~ Error primitive sort Set expects exactly one generic argument but found 2
1
}

fn foo6(x: real<bool>) -> real { //~ Error primitive sort real expects no generics but found 1
1
}

fn foo7(x: bool<int>) -> real { //~ Error primitive sort bool expects no generics but found 1
1
}
}

#[flux::refined_by(f: T<int>)] //~ Error type parameter expects no generics but found 1
struct X<T> {
#[flux::field(T[f])]
f: T
}

#[flux::assoc(fn foo(x: Self<int>) -> 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<int>)] //~ Error type parameter expects no generics but found 1
struct Y {}

0 comments on commit 8b96f46

Please sign in to comment.