stylistic improvements

This commit is contained in:
Folkert 2020-04-05 14:33:02 +02:00
parent 17d11adb98
commit 854ffdae5e
3 changed files with 71 additions and 74 deletions

View file

@ -329,11 +329,11 @@ where
Url => { Url => {
self.write_str("<")?; self.write_str("<")?;
} }
GlobalTag | PrivateTag | Keyword => { GlobalTag | PrivateTag | Keyword | RecordField | Symbol => {
self.write_str("`")?; self.write_str("`")?;
} }
CodeBlock | PlainText | LineNumber | Error | GutterBar | TypeVariable | Alias CodeBlock | PlainText | LineNumber | Error | GutterBar | TypeVariable | Alias
| RecordField | Module | Structure | Symbol | BinOp => {} | Module | Structure | BinOp => {}
} }
self.style_stack.push(*annotation); self.style_stack.push(*annotation);
Ok(()) Ok(())
@ -351,11 +351,11 @@ where
Url => { Url => {
self.write_str(">")?; self.write_str(">")?;
} }
GlobalTag | PrivateTag | Keyword => { GlobalTag | PrivateTag | Keyword | RecordField | Symbol => {
self.write_str("`")?; self.write_str("`")?;
} }
CodeBlock | PlainText | LineNumber | Error | GutterBar | TypeVariable | Alias CodeBlock | PlainText | LineNumber | Error | GutterBar | TypeVariable | Alias
| RecordField | Module | Structure | Symbol | BinOp => {} | Module | Structure | BinOp => {}
}, },
} }
Ok(()) Ok(())

View file

@ -130,7 +130,7 @@ fn to_expr_report(
keyword_text("if"), keyword_text("if"),
plain_text(" condition needs to be a "), plain_text(" condition needs to be a "),
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)), ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
plain_text("."), plain_text(":"),
]); ]);
report_bad_type( report_bad_type(
@ -143,7 +143,7 @@ fn to_expr_report(
problem, problem,
plain_text("Right now its"), plain_text("Right now its"),
Concat(vec![ Concat(vec![
plain_text("but I need every "), plain_text("But I need every "),
keyword_text("if"), keyword_text("if"),
plain_text(" condition to evaluate to a "), plain_text(" condition to evaluate to a "),
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)), ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
@ -167,7 +167,7 @@ fn to_expr_report(
keyword_text("if"), keyword_text("if"),
plain_text(" guard condition needs to be a "), plain_text(" guard condition needs to be a "),
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)), ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
plain_text("."), plain_text(":"),
]); ]);
report_bad_type( report_bad_type(
filename, filename,
@ -179,7 +179,7 @@ fn to_expr_report(
problem, problem,
plain_text("Right now its"), plain_text("Right now its"),
Concat(vec![ Concat(vec![
plain_text("but I need every "), plain_text("But I need every "),
keyword_text("if"), keyword_text("if"),
plain_text(" guard condition to evaluate to a "), plain_text(" guard condition to evaluate to a "),
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)), ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
@ -219,10 +219,10 @@ fn to_expr_report(
Concat(vec![ Concat(vec![
plain_text("but the "), plain_text("but the "),
keyword_text("then"), keyword_text("then"),
plain_text(" branch has the type"), plain_text(" branch has the type:"),
]), ]),
Concat(vec![ Concat(vec![
plain_text("instead. I need all branches in an "), plain_text("I need all branches in an "),
keyword_text("if"), keyword_text("if"),
plain_text(" to have the same type!"), plain_text(" to have the same type!"),
]), ]),
@ -242,9 +242,9 @@ fn to_expr_report(
ith ith
)), )),
plain_text(&format!("The {} branch is", ith)), plain_text(&format!("The {} branch is", ith)),
plain_text("but all the previous branches have the type"), plain_text("But all the previous branches have type:"),
Concat(vec![ Concat(vec![
plain_text("instead. I need all branches in an "), plain_text("I need all branches in an "),
keyword_text("if"), keyword_text("if"),
plain_text(" to have the same type!"), plain_text(" to have the same type!"),
]), ]),
@ -266,12 +266,12 @@ fn to_expr_report(
Concat(vec![ Concat(vec![
plain_text(&format!("The {} branch of this ", ith)), plain_text(&format!("The {} branch of this ", ith)),
keyword_text("when"), keyword_text("when"),
plain_text(" does not match all the previous branches"), plain_text(" does not match all the previous branches:"),
]), ]),
plain_text(&format!("The {} branch is", ith)), plain_text(&format!("The {} branch is", ith)),
plain_text("but all the previous branches have type"), plain_text("But all the previous branches have type:"),
Concat(vec![ Concat(vec![
plain_text("instead. I need all branches of a "), plain_text("I need all branches of a "),
keyword_text("when"), keyword_text("when"),
plain_text(" to have the same type!"), plain_text(" to have the same type!"),
]), ]),
@ -290,12 +290,12 @@ fn to_expr_report(
region, region,
Some(expr_region), Some(expr_region),
plain_text(&format!( plain_text(&format!(
"The {} element of this list does not match all the previous elements", "The {} element of this list does not match all the previous elements:",
ith ith
)), )),
plain_text(&format!("The {} element is", ith)), plain_text(&format!("The {} element is", ith)),
plain_text("but all the previous elements in the list have type"), plain_text("But all the previous elements in the list have type:"),
plain_text("instead. I need all elements of a list to have the same type!"), plain_text("I need all elements of a list to have the same type!"),
) )
} }
Reason::RecordUpdateValue(field) => report_mismatch( Reason::RecordUpdateValue(field) => report_mismatch(
@ -308,15 +308,15 @@ fn to_expr_report(
Concat(vec![ Concat(vec![
plain_text("I cannot update the "), plain_text("I cannot update the "),
record_field_text(field.as_str()), record_field_text(field.as_str()),
plain_text(" field like this"), plain_text(" field like this:"),
]), ]),
Concat(vec![ Concat(vec![
plain_text("You are trying to update "), plain_text("You are trying to update "),
record_field_text(field.as_str()), record_field_text(field.as_str()),
plain_text(" to be"), plain_text(" to be"),
]), ]),
plain_text("But it should be"), plain_text("But it should be:"),
plain_text("instead. Record update syntax does not allow you to change the type of fields. You can achieve that with record literal syntax."), plain_text("Record update syntax does not allow you to change the type of fields. You can achieve that with record literal syntax."),
), ),
other => { other => {
// AnonymousFnArg { arg_index: u8 }, // AnonymousFnArg { arg_index: u8 },
@ -403,64 +403,64 @@ fn add_category(this_is: ReportText, category: &Category) -> ReportText {
Lookup(name) => Concat(vec![ Lookup(name) => Concat(vec![
plain_text("This "), plain_text("This "),
Value(*name), Value(*name),
plain_text(" value is a"), plain_text(" value is a:"),
]), ]),
If => Concat(vec![ If => Concat(vec![
plain_text("This "), plain_text("This "),
keyword_text("if"), keyword_text("if"),
plain_text("expression produces"), plain_text("expression produces:"),
]), ]),
When => Concat(vec![ When => Concat(vec![
plain_text("This "), plain_text("This "),
keyword_text("when"), keyword_text("when"),
plain_text("expression produces"), plain_text("expression produces:"),
]), ]),
List => Concat(vec![this_is, plain_text(" a list of type")]), List => Concat(vec![this_is, plain_text(" a list of type:")]),
Num => Concat(vec![this_is, plain_text(" a number of type")]), Num => Concat(vec![this_is, plain_text(" a number of type:")]),
Int => Concat(vec![this_is, plain_text(" an integer of type")]), Int => Concat(vec![this_is, plain_text(" an integer of type:")]),
Float => Concat(vec![this_is, plain_text(" a float of type")]), Float => Concat(vec![this_is, plain_text(" a float of type:")]),
Str => Concat(vec![this_is, plain_text(" a string of type")]), Str => Concat(vec![this_is, plain_text(" a string of type:")]),
Lambda => Concat(vec![this_is, plain_text("an anonymous function of type")]), Lambda => Concat(vec![this_is, plain_text("an anonymous function of type:")]),
TagApply(TagName::Global(name)) => Concat(vec![ TagApply(TagName::Global(name)) => Concat(vec![
plain_text("This "), plain_text("This "),
global_tag_text(name.as_str()), global_tag_text(name.as_str()),
plain_text(" global tag application produces"), plain_text(" global tag application produces:"),
]), ]),
TagApply(TagName::Private(name)) => Concat(vec![ TagApply(TagName::Private(name)) => Concat(vec![
plain_text("This "), plain_text("This "),
private_tag_text(*name), private_tag_text(*name),
plain_text(" private tag application produces"), plain_text(" private tag application produces:"),
]), ]),
Record => Concat(vec![this_is, plain_text(" a record of type")]), Record => Concat(vec![this_is, plain_text(" a record of type:")]),
Accessor(field) => Concat(vec![ Accessor(field) => Concat(vec![
plain_text("This "), plain_text("This "),
record_field_text(field.as_str()), record_field_text(field.as_str()),
plain_text(" value is a"), plain_text(" value is a:"),
]), ]),
Access(field) => Concat(vec![ Access(field) => Concat(vec![
plain_text("The value at "), plain_text("The value at "),
record_field_text(field.as_str()), record_field_text(field.as_str()),
plain_text(" is a"), plain_text(" is a:"),
]), ]),
CallResult(Some(symbol)) => Concat(vec![ CallResult(Some(symbol)) => Concat(vec![
plain_text("This "), plain_text("This "),
Value(*symbol), Value(*symbol),
plain_text(" call produces"), plain_text(" call produces:"),
]), ]),
CallResult(None) => Concat(vec![this_is]), CallResult(None) => Concat(vec![this_is, plain_text(":")]),
Uniqueness => Concat(vec![ Uniqueness => Concat(vec![
this_is, this_is,
plain_text(" an uniqueness attribute of type"), plain_text(" an uniqueness attribute of type:"),
]), ]),
Storage => Concat(vec![this_is, plain_text(" a value of type")]), Storage => Concat(vec![this_is, plain_text(" a value of type:")]),
} }
} }

View file

@ -222,7 +222,7 @@ mod test_reporting {
.text .text
.render_ci(&mut buf, &mut subs, home, &src_lines, &interns); .render_ci(&mut buf, &mut subs, home, &src_lines, &interns);
assert_eq!(buf, "x"); assert_eq!(buf, "`x`");
} }
#[test] #[test]
@ -296,12 +296,12 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
y is not used anywhere in your code. `y` is not used anywhere in your code.
2 y = 2 2 y = 2
^ ^
If you didn't intend on using y then remove it so future readers of your code don't wonder why it is there."# If you didn't intend on using `y` then remove it so future readers of your code don't wonder why it is there."#
), ),
) )
} }
@ -860,16 +860,16 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
This `if` condition needs to be a Bool. This `if` condition needs to be a Bool:
1 if "foo" then 2 else 3 1 if "foo" then 2 else 3
^^^^^ ^^^^^
Right now its a string of type Right now its a string of type:
Str Str
but I need every `if` condition to evaluate to a Booleither `True` or `False`. But I need every `if` condition to evaluate to a Booleither `True` or `False`.
"# "#
), ),
) )
@ -887,16 +887,16 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
This `if` guard condition needs to be a Bool. This `if` guard condition needs to be a Bool:
2 2 if 1 -> 0x0 2 2 if 1 -> 0x0
^ ^
Right now its a number of type Right now its a number of type:
Num a Num a
but I need every `if` guard condition to evaluate to a Booleither `True` or `False`. But I need every `if` guard condition to evaluate to a Booleither `True` or `False`.
"# "#
), ),
) )
@ -917,15 +917,15 @@ mod test_reporting {
1 if True then 2 else "foo" 1 if True then 2 else "foo"
^^^^^ ^^^^^
The `else` branch is a string of type The `else` branch is a string of type:
Str Str
but the `then` branch has the type but the `then` branch has the type:
Num a Num a
instead. I need all branches in an `if` to have the same type! I need all branches in an `if` to have the same type!
"# "#
), ),
) )
@ -950,12 +950,10 @@ mod test_reporting {
// Str // Str
// but all the previous branches have the type // But all the previous branches have the type
// Num a // Num a
// instead.
// "# // "#
// ), // ),
// ) // )
@ -973,20 +971,20 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
The 2nd branch of this `when` does not match all the previous branches The 2nd branch of this `when` does not match all the previous branches:
3 3 -> {} 3 3 -> {}
^^ ^^
The 2nd branch is a record of type The 2nd branch is a record of type:
{} {}
but all the previous branches have type But all the previous branches have type:
Str Str
instead. I need all branches of a `when` to have the same type! I need all branches of a `when` to have the same type!
"# "#
), ),
) )
@ -1002,20 +1000,20 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
The 3rd element of this list does not match all the previous elements The 3rd element of this list does not match all the previous elements:
1 [ 1, 3, "foo" ] 1 [ 1, 3, "foo" ]
^^^^^ ^^^^^
The 3rd element is a string of type The 3rd element is a string of type:
Str Str
but all the previous elements in the list have type But all the previous elements in the list have type:
Num a Num a
instead. I need all elements of a list to have the same type! I need all elements of a list to have the same type!
"# "#
), ),
) )
@ -1034,20 +1032,20 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
I cannot update the .foo field like this I cannot update the `.foo` field like this:
4 { x & foo: "bar" } 4 { x & foo: "bar" }
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
You are trying to update .foo to be a string of type You are trying to update `.foo` to be a string of type:
Str Str
But it should be But it should be:
{} {}
instead. Record update syntax does not allow you to change the type of fields. You can achieve that with record literal syntax. Record update syntax does not allow you to change the type of fields. You can achieve that with record literal syntax.
"# "#
), ),
) )
@ -1067,12 +1065,12 @@ mod test_reporting {
// ), // ),
// indoc!( // indoc!(
// r#" // r#"
// The `x` record does not have a `baz` field // The `x` record does not have a `baz` field:
// //
// 4 ┆ { x & baz: "bar" } // 4 ┆ { x & baz: "bar" }
// ┆ ^^^ // ┆ ^^^
// //
// This is usually a typo. Here are the `x` fields that are most similar // This is usually a typo. Here are the `x` fields that are most similar:
// //
// { foo : {} // { foo : {}
// } // }
@ -1096,20 +1094,19 @@ mod test_reporting {
// ), // ),
// indoc!( // indoc!(
// r#" // r#"
// Something is off with the body of the `x` definition // Something is off with the body of the `x` definition:
// //
// 4 ┆ x = 4 // 4 ┆ x = 4
// ┆ ^ // ┆ ^
// //
// The body is a number of type // The body is a number of type:
// //
// Num a // Num a
// //
// But the type annotation on `x` says that it should be // But the type annotation on `x` says that it should be:
// //
// Str // Str
// //
// instead.
// "# // "#
// ), // ),
// ) // )
@ -1127,7 +1124,7 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
I'm inferring a weird self-referential type for g: I'm inferring a weird self-referential type for `g`:
1 f = \g -> g g 1 f = \g -> g g
^ ^
@ -1152,7 +1149,7 @@ mod test_reporting {
), ),
indoc!( indoc!(
r#" r#"
I'm inferring a weird self-referential type for f: I'm inferring a weird self-referential type for `f`:
1 f = \x -> f [x] 1 f = \x -> f [x]
^ ^