diff --git a/fathom/src/surface/elaboration.rs b/fathom/src/surface/elaboration.rs index b01315a94..9f84c5aae 100644 --- a/fathom/src/surface/elaboration.rs +++ b/fathom/src/surface/elaboration.rs @@ -1332,20 +1332,16 @@ impl<'arena> Context<'arena> { return (core::Term::Prim(file_range.into(), prim), r#type.clone()); } - let candidates = self - .local_env - .names - .iter() - .flatten() - .copied() - .chain(self.item_env.names.iter().copied()); - let suggestion = suggest_name(*name, candidates); - self.push_message(Message::UnboundName { range: file_range, name: *name, - suggestion, + suggested_name: { + let item_names = self.item_env.names.iter().copied(); + let local_names = self.local_env.names.iter().flatten().copied(); + suggest_name(*name, item_names.chain(local_names)) + }, }); + self.synth_reported_error(*range) } Term::Hole(_, name) => { @@ -1662,7 +1658,7 @@ impl<'arena> Context<'arena> { head_type: self.pretty_value(&head_type), label_range: self.file_range(*label_range), label: *proj_label, - suggestion: suggest_name(*proj_label, labels.iter().map(|(_, l)| *l)), + suggested_label: suggest_name(*proj_label, labels.iter().map(|(_, l)| *l)), }); return self.synth_reported_error(*range); } diff --git a/fathom/src/surface/elaboration/reporting.rs b/fathom/src/surface/elaboration/reporting.rs index 8d2948244..db6c9f741 100644 --- a/fathom/src/surface/elaboration/reporting.rs +++ b/fathom/src/surface/elaboration/reporting.rs @@ -15,7 +15,7 @@ pub enum Message { UnboundName { range: FileRange, name: Symbol, - suggestion: Option, + suggested_name: Option, }, RefutablePattern { pattern_range: FileRange, @@ -47,7 +47,7 @@ pub enum Message { head_type: String, label_range: FileRange, label: Symbol, - suggestion: Option, + suggested_label: Option, }, MismatchedFieldLabels { range: FileRange, @@ -148,7 +148,7 @@ impl Message { Message::UnboundName { range, name, - suggestion, + suggested_name, } => { let name = name.resolve(); @@ -156,11 +156,9 @@ impl Message { .with_message(format!("cannot find `{name}` in scope")) .with_labels(vec![primary_label(range).with_message("unbound name")]); - if let Some(suggestion) = suggestion { - diagnostic = diagnostic.with_notes(vec![format!( - "help: did you mean `{}`?", - suggestion.resolve() - )]) + if let Some(name) = suggested_name { + diagnostic = diagnostic + .with_notes(vec![format!("help: did you mean `{}`?", name.resolve())]) } diagnostic } @@ -219,7 +217,7 @@ impl Message { head_type, label_range, label, - suggestion, + suggested_label, } => { let label = label.resolve(); @@ -230,12 +228,12 @@ impl Message { secondary_label(head_range) .with_message(format!("expression of type {head_type}")), ]); - if let Some(suggestion) = suggestion { - diagnostic = diagnostic.with_notes(vec![format!( - "help: did you mean `{}`?", - suggestion.resolve() - )]); + + if let Some(label) = suggested_label { + diagnostic = diagnostic + .with_notes(vec![format!("help: did you mean `{}`?", label.resolve())]); } + diagnostic } Message::MismatchedFieldLabels {