mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Revise record field typo error report
This commit is contained in:
parent
9343c6802a
commit
ab44f23e0f
1 changed files with 104 additions and 109 deletions
|
@ -827,10 +827,8 @@ fn to_expr_report<'b>(
|
|||
You can achieve that with record literal syntax.",
|
||||
)),
|
||||
),
|
||||
Reason::RecordUpdateKeys(symbol, expected_fields) => match found
|
||||
.clone()
|
||||
.unwrap_structural_alias()
|
||||
{
|
||||
Reason::RecordUpdateKeys(symbol, expected_fields) => {
|
||||
match found.clone().unwrap_structural_alias() {
|
||||
ErrorType::Record(actual_fields, ext) => {
|
||||
let expected_set: MutSet<_> = expected_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)) => {
|
||||
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![
|
||||
alloc.reflow("The "),
|
||||
|
@ -888,7 +886,7 @@ fn to_expr_report<'b>(
|
|||
|
||||
alloc.stack(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,
|
||||
alloc.reflow(" fields that are most similar:"),
|
||||
]),
|
||||
|
@ -902,7 +900,8 @@ fn to_expr_report<'b>(
|
|||
alloc.reflow("So maybe "),
|
||||
f_doc,
|
||||
alloc.reflow(" should be "),
|
||||
alloc.record_field(f.0),
|
||||
alloc.type_variable(f.0),
|
||||
//alloc.record_field(f.0),
|
||||
alloc.reflow("?"),
|
||||
]),
|
||||
])
|
||||
|
@ -931,7 +930,8 @@ fn to_expr_report<'b>(
|
|||
alloc.reflow("It is"),
|
||||
alloc.reflow("But I need a record!"),
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
Reason::FnCall { name, arity } => match count_arguments(&found) {
|
||||
0 => {
|
||||
let this_value = match name {
|
||||
|
@ -2956,23 +2956,18 @@ mod report_text {
|
|||
) -> RocDocBuilder<'b> {
|
||||
let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| {
|
||||
field_name
|
||||
.indent(4)
|
||||
.append(alloc.text(" : "))
|
||||
.hang(4)
|
||||
.append(field_type)
|
||||
.append(alloc.text(","))
|
||||
};
|
||||
|
||||
let field = alloc.reflow("{ ").append(entry_to_doc(entry));
|
||||
let fields = std::iter::repeat(alloc.reflow(", "))
|
||||
.zip(
|
||||
entries
|
||||
.into_iter()
|
||||
.map(entry_to_doc)
|
||||
.chain(std::iter::once(alloc.text("..."))),
|
||||
)
|
||||
.map(|(a, b)| a.append(b));
|
||||
let fields = std::iter::once(entry_to_doc(entry))
|
||||
.chain(entries.into_iter().map(entry_to_doc))
|
||||
.chain(std::iter::once(alloc.text("…").indent(4)));
|
||||
|
||||
alloc.vcat(
|
||||
std::iter::once(field)
|
||||
std::iter::once(alloc.reflow("{"))
|
||||
.chain(fields)
|
||||
.chain(std::iter::once(alloc.text("}"))),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue