Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functional updates #879

Merged
merged 16 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve invalid field error message
  • Loading branch information
vrindisbacher committed Nov 18, 2024
commit 9b16d5b6bed55ae8eb8842575afb043d1bbb2f1b
14 changes: 0 additions & 14 deletions crates/flux-fhir-analysis/src/wf/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,6 @@ impl<'a> UnexpectedConstructor<'a> {
}
}

#[derive(Diagnostic)]
#[diag(fhir_analysis_invalid_field_update, code = E0999)]
pub(super) struct InvalidFieldUpdate {
#[primary_span]
#[label]
span: Span,
}

impl InvalidFieldUpdate {
pub(super) fn new(span: Span) -> Self {
Self { span }
}
}

#[derive(Diagnostic)]
#[diag(fhir_analysis_param_count_mismatch, code = E0999)]
pub(super) struct ParamCountMismatch {
Expand Down
4 changes: 3 additions & 1 deletion crates/flux-fhir-analysis/src/wf/sortck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@
if let Some(idx) = field_names.iter().position(|s| *s == expr.ident.name) {
// check that field sort is the same as the expr sort
let sort = &sorts[idx];
self.check_expr(&expr.expr, sort)?

Check warning on line 103 in crates/flux-fhir-analysis/src/wf/sortck.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> crates/flux-fhir-analysis/src/wf/sortck.rs:103:21 | 103 | self.check_expr(&expr.expr, sort)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.check_expr(&expr.expr, sort)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
} else {
// emit an error because we have a mismatched field
return Err(self.emit_err(errors::InvalidFieldUpdate::new(expr.ident.span)));
return Err(
self.emit_err(errors::FieldNotFound::new(expected.clone(), expr.ident))
);
}
}
Ok(())
Expand Down Expand Up @@ -171,7 +173,7 @@
}
fhir::ExprKind::Record(fields) => self.check_record(expr, fields, expected)?,
fhir::ExprKind::Constructor(_path, exprs, spread) => {
self.check_constructor(expr.span, exprs, spread, expected)?

Check warning on line 176 in crates/flux-fhir-analysis/src/wf/sortck.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> crates/flux-fhir-analysis/src/wf/sortck.rs:176:17 | 176 | self.check_constructor(expr.span, exprs, spread, expected)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.check_constructor(expr.span, exprs, spread, expected)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/neg/error_messages/wf/constructor01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct X {
}

// z is not a valid field for X
#[flux::sig(fn (x: X[@old_x]) -> X[X { y: 2, x: 1, z: 3 }])] //~ ERROR invalid field referenced in constructor
#[flux::sig(fn (x: X[@old_x]) -> X[X { y: 2, x: 1, z: 3 }])] //~ ERROR no field `z` on sort `X`
fn f1(mut x: X) -> X {
x.x = 1;
x.y = 2;
Expand Down
Loading