Revise record field typo error report

This commit is contained in:
Richard Feldman 2022-04-19 18:18:34 -04:00
parent 9343c6802a
commit ab44f23e0f
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -827,10 +827,8 @@ fn to_expr_report<'b>(
You can achieve that with record literal syntax.", You can achieve that with record literal syntax.",
)), )),
), ),
Reason::RecordUpdateKeys(symbol, expected_fields) => match found Reason::RecordUpdateKeys(symbol, expected_fields) => {
.clone() match found.clone().unwrap_structural_alias() {
.unwrap_structural_alias()
{
ErrorType::Record(actual_fields, ext) => { ErrorType::Record(actual_fields, ext) => {
let expected_set: MutSet<_> = expected_fields.keys().cloned().collect(); let expected_set: MutSet<_> = expected_fields.keys().cloned().collect();
let actual_set: MutSet<_> = actual_fields.keys().cloned().collect(); let actual_set: MutSet<_> = actual_fields.keys().cloned().collect();
@ -858,7 +856,7 @@ fn to_expr_report<'b>(
), ),
Some((field, field_region)) => { Some((field, field_region)) => {
let r_doc = alloc.symbol_unqualified(symbol); let r_doc = alloc.symbol_unqualified(symbol);
let f_doc = alloc.record_field(field.clone()); let f_doc = alloc.type_variable(field.clone());
let header = alloc.concat(vec![ let header = alloc.concat(vec![
alloc.reflow("The "), alloc.reflow("The "),
@ -888,7 +886,7 @@ fn to_expr_report<'b>(
alloc.stack(vec![ alloc.stack(vec![
alloc.concat(vec![ alloc.concat(vec![
alloc.reflow("This is usually a typo. Here are the "), alloc.reflow("There may be a typo. Here are the "),
r_doc, r_doc,
alloc.reflow(" fields that are most similar:"), alloc.reflow(" fields that are most similar:"),
]), ]),
@ -902,7 +900,8 @@ fn to_expr_report<'b>(
alloc.reflow("So maybe "), alloc.reflow("So maybe "),
f_doc, f_doc,
alloc.reflow(" should be "), alloc.reflow(" should be "),
alloc.record_field(f.0), alloc.type_variable(f.0),
//alloc.record_field(f.0),
alloc.reflow("?"), alloc.reflow("?"),
]), ]),
]) ])
@ -931,7 +930,8 @@ fn to_expr_report<'b>(
alloc.reflow("It is"), alloc.reflow("It is"),
alloc.reflow("But I need a record!"), alloc.reflow("But I need a record!"),
), ),
}, }
}
Reason::FnCall { name, arity } => match count_arguments(&found) { Reason::FnCall { name, arity } => match count_arguments(&found) {
0 => { 0 => {
let this_value = match name { let this_value = match name {
@ -2956,23 +2956,18 @@ mod report_text {
) -> RocDocBuilder<'b> { ) -> RocDocBuilder<'b> {
let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| { let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| {
field_name field_name
.indent(4)
.append(alloc.text(" : ")) .append(alloc.text(" : "))
.hang(4)
.append(field_type) .append(field_type)
.append(alloc.text(","))
}; };
let field = alloc.reflow("{ ").append(entry_to_doc(entry)); let fields = std::iter::once(entry_to_doc(entry))
let fields = std::iter::repeat(alloc.reflow(", ")) .chain(entries.into_iter().map(entry_to_doc))
.zip( .chain(std::iter::once(alloc.text("").indent(4)));
entries
.into_iter()
.map(entry_to_doc)
.chain(std::iter::once(alloc.text("..."))),
)
.map(|(a, b)| a.append(b));
alloc.vcat( alloc.vcat(
std::iter::once(field) std::iter::once(alloc.reflow("{"))
.chain(fields) .chain(fields)
.chain(std::iter::once(alloc.text("}"))), .chain(std::iter::once(alloc.text("}"))),
) )