Skip to content

Commit c920aba

Browse files
committed
Tidy up name suggestions
Breaks up the long, vertical method chain into some separate definitions, and tweaks the field names in the related messages for clarity.
1 parent 8446cb2 commit c920aba

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

fathom/src/surface/elaboration.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,20 +1332,16 @@ impl<'arena> Context<'arena> {
13321332
return (core::Term::Prim(file_range.into(), prim), r#type.clone());
13331333
}
13341334

1335-
let candidates = self
1336-
.local_env
1337-
.names
1338-
.iter()
1339-
.flatten()
1340-
.copied()
1341-
.chain(self.item_env.names.iter().copied());
1342-
let suggestion = suggest_name(*name, candidates);
1343-
13441335
self.push_message(Message::UnboundName {
13451336
range: file_range,
13461337
name: *name,
1347-
suggestion,
1338+
suggested_name: {
1339+
let item_names = self.item_env.names.iter().copied();
1340+
let local_names = self.local_env.names.iter().flatten().copied();
1341+
suggest_name(*name, item_names.chain(local_names))
1342+
},
13481343
});
1344+
13491345
self.synth_reported_error(*range)
13501346
}
13511347
Term::Hole(_, name) => {
@@ -1662,7 +1658,7 @@ impl<'arena> Context<'arena> {
16621658
head_type: self.pretty_value(&head_type),
16631659
label_range: self.file_range(*label_range),
16641660
label: *proj_label,
1665-
suggestion: suggest_name(*proj_label, labels.iter().map(|(_, l)| *l)),
1661+
suggested_label: suggest_name(*proj_label, labels.iter().map(|(_, l)| *l)),
16661662
});
16671663
return self.synth_reported_error(*range);
16681664
}

fathom/src/surface/elaboration/reporting.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum Message {
1515
UnboundName {
1616
range: FileRange,
1717
name: Symbol,
18-
suggestion: Option<Symbol>,
18+
suggested_name: Option<Symbol>,
1919
},
2020
RefutablePattern {
2121
pattern_range: FileRange,
@@ -47,7 +47,7 @@ pub enum Message {
4747
head_type: String,
4848
label_range: FileRange,
4949
label: Symbol,
50-
suggestion: Option<Symbol>,
50+
suggested_label: Option<Symbol>,
5151
},
5252
MismatchedFieldLabels {
5353
range: FileRange,
@@ -148,19 +148,17 @@ impl Message {
148148
Message::UnboundName {
149149
range,
150150
name,
151-
suggestion,
151+
suggested_name,
152152
} => {
153153
let name = name.resolve();
154154

155155
let mut diagnostic = Diagnostic::error()
156156
.with_message(format!("cannot find `{name}` in scope"))
157157
.with_labels(vec![primary_label(range).with_message("unbound name")]);
158158

159-
if let Some(suggestion) = suggestion {
160-
diagnostic = diagnostic.with_notes(vec![format!(
161-
"help: did you mean `{}`?",
162-
suggestion.resolve()
163-
)])
159+
if let Some(name) = suggested_name {
160+
diagnostic = diagnostic
161+
.with_notes(vec![format!("help: did you mean `{}`?", name.resolve())])
164162
}
165163
diagnostic
166164
}
@@ -219,7 +217,7 @@ impl Message {
219217
head_type,
220218
label_range,
221219
label,
222-
suggestion,
220+
suggested_label,
223221
} => {
224222
let label = label.resolve();
225223

@@ -230,12 +228,12 @@ impl Message {
230228
secondary_label(head_range)
231229
.with_message(format!("expression of type {head_type}")),
232230
]);
233-
if let Some(suggestion) = suggestion {
234-
diagnostic = diagnostic.with_notes(vec![format!(
235-
"help: did you mean `{}`?",
236-
suggestion.resolve()
237-
)]);
231+
232+
if let Some(label) = suggested_label {
233+
diagnostic = diagnostic
234+
.with_notes(vec![format!("help: did you mean `{}`?", label.resolve())]);
238235
}
236+
239237
diagnostic
240238
}
241239
Message::MismatchedFieldLabels {

0 commit comments

Comments
 (0)