Suggest tags of primitive types when an ident is misspelled

With this change, mispellings of things like `true` and `false` will
include a hint to the user that they may want to use `True` and `False`,
respectively, instead.

There are a few ways to implement this, but exposing these common tags
(which compose builtin type aliases) seems the easiest, least expensive,
and doesn't break anything for now.
This commit is contained in:
ayazhafiz 2021-11-17 20:57:19 -05:00
parent 5b19337089
commit c156f61b0f
2 changed files with 47 additions and 15 deletions

View file

@ -989,12 +989,14 @@ define_builtins! {
} }
2 BOOL: "Bool" => { 2 BOOL: "Bool" => {
0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias 0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias
1 BOOL_AND: "and" 1 BOOL_FALSE: "False" imported // Bool.Bool = [ False, True ]
2 BOOL_OR: "or" 2 BOOL_TRUE: "True" imported // Bool.Bool = [ False, True ]
3 BOOL_NOT: "not" 3 BOOL_AND: "and"
4 BOOL_XOR: "xor" 4 BOOL_OR: "or"
5 BOOL_EQ: "isEq" 5 BOOL_NOT: "not"
6 BOOL_NEQ: "isNotEq" 6 BOOL_XOR: "xor"
7 BOOL_EQ: "isEq"
8 BOOL_NEQ: "isNotEq"
} }
3 STR: "Str" => { 3 STR: "Str" => {
0 STR_STR: "Str" imported // the Str.Str type alias 0 STR_STR: "Str" imported // the Str.Str type alias
@ -1077,12 +1079,14 @@ define_builtins! {
} }
5 RESULT: "Result" => { 5 RESULT: "Result" => {
0 RESULT_RESULT: "Result" imported // the Result.Result type alias 0 RESULT_RESULT: "Result" imported // the Result.Result type alias
1 RESULT_MAP: "map" 1 RESULT_OK: "Ok" imported // Result.Result = [ Ok a, Err e ]
2 RESULT_MAP_ERR: "mapErr" 2 RESULT_ERR: "Err" imported // Result.Result = [ Ok a, Err e ]
3 RESULT_WITH_DEFAULT: "withDefault" 3 RESULT_MAP: "map"
4 RESULT_AFTER: "after" 4 RESULT_MAP_ERR: "mapErr"
5 RESULT_IS_OK: "isOk" 5 RESULT_WITH_DEFAULT: "withDefault"
6 RESULT_IS_ERR: "isErr" 6 RESULT_AFTER: "after"
7 RESULT_IS_OK: "isOk"
8 RESULT_IS_ERR: "isErr"
} }
6 DICT: "Dict" => { 6 DICT: "Dict" => {
0 DICT_DICT: "Dict" imported // the Dict.Dict type alias 0 DICT_DICT: "Dict" imported // the Dict.Dict type alias

View file

@ -547,7 +547,35 @@ mod test_reporting {
baz baz
Nat Nat
Str Str
U8 Err
"#
),
)
}
#[test]
fn lowercase_primitive_tag_bool() {
report_problem_as(
indoc!(
r#"
if true then 1 else 2
"#
),
indoc!(
r#"
UNRECOGNIZED NAME
I cannot find a `true` value
1 if true then 1 else 2
^^^^
Did you mean one of these?
True
Str
Num
Err
"# "#
), ),
) )
@ -1950,10 +1978,10 @@ mod test_reporting {
Did you mean one of these? Did you mean one of these?
Ok
U8 U8
f f
I8 I8
F64
"# "#
), ),
) )
@ -5802,8 +5830,8 @@ mod test_reporting {
Nat Nat
Str Str
Err
U8 U8
F64
"# "#
), ),
) )