mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Use ':' and '.' contextually in error messages
e.g. record update errors complain about 'foo:' being wrong, whereas record access errors complain about '.foo' being wrong.
This commit is contained in:
parent
fdb378f859
commit
5562121006
@ -455,7 +455,9 @@ fn to_expr_report<'b>(
|
||||
lines,
|
||||
filename,
|
||||
opt_sym,
|
||||
".",
|
||||
field,
|
||||
"",
|
||||
expr_region,
|
||||
found_fields,
|
||||
found_ext,
|
||||
@ -888,7 +890,9 @@ fn to_expr_report<'b>(
|
||||
lines,
|
||||
filename,
|
||||
Some(symbol),
|
||||
"",
|
||||
field,
|
||||
":",
|
||||
*field_region,
|
||||
actual_fields,
|
||||
ext,
|
||||
@ -3280,16 +3284,18 @@ fn report_record_field_typo<'b>(
|
||||
lines: &LineInfo,
|
||||
filename: PathBuf,
|
||||
opt_sym: Option<Symbol>,
|
||||
field_prefix: &str,
|
||||
field: &Lowercase,
|
||||
field_suffix: &str,
|
||||
field_region: Region,
|
||||
actual_fields: SendMap<Lowercase, RecordField<ErrorType>>,
|
||||
ext: TypeExt,
|
||||
) -> Report<'b> {
|
||||
let f_doc = alloc
|
||||
.text(field.as_str().to_string())
|
||||
.annotate(Annotation::Typo);
|
||||
|
||||
let header = {
|
||||
let f_doc = alloc
|
||||
.text(field.as_str().to_string())
|
||||
.annotate(Annotation::Typo);
|
||||
|
||||
let r_doc = match opt_sym {
|
||||
Some(symbol) => alloc.symbol_unqualified(symbol).append(" "),
|
||||
None => alloc.text(""),
|
||||
@ -3299,7 +3305,7 @@ fn report_record_field_typo<'b>(
|
||||
alloc.reflow("This "),
|
||||
r_doc,
|
||||
alloc.reflow("record doesn’t have a "),
|
||||
f_doc.clone(),
|
||||
f_doc,
|
||||
alloc.reflow(" field:"),
|
||||
])
|
||||
};
|
||||
@ -3325,6 +3331,10 @@ fn report_record_field_typo<'b>(
|
||||
} else {
|
||||
let f = suggestions.remove(0);
|
||||
let fs = suggestions;
|
||||
let f_doc = alloc
|
||||
.text(format!("{}{}{}", field_prefix, field, field_suffix))
|
||||
.annotate(Annotation::Typo);
|
||||
|
||||
let r_doc = match opt_sym {
|
||||
Some(symbol) => alloc.symbol_unqualified(symbol).append(" fields"),
|
||||
None => alloc.text("fields on the record"),
|
||||
@ -3342,9 +3352,9 @@ fn report_record_field_typo<'b>(
|
||||
f_doc,
|
||||
alloc.reflow(" should be "),
|
||||
alloc
|
||||
.text(f.0.as_str().to_string())
|
||||
.text(format!("{}{}{}", field_prefix, f.0, field_suffix))
|
||||
.annotate(Annotation::TypoSuggestion),
|
||||
alloc.reflow("?"),
|
||||
alloc.reflow(" instead?"),
|
||||
]),
|
||||
])
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user