Skip to content

Commit 3a3a5a5

Browse files
Wilfredfacebook-github-bot
authored andcommitted
Offer 'did you mean' suggestions case-insensitively
Summary: Don't consider case when trying to find the most similar item in naming suggestions. Reviewed By: vsiles Differential Revision: D39328377 fbshipit-source-id: 3b2f21c233cce801c8b35621f41be643e0a37708
1 parent ed46335 commit 3a3a5a5

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

hphp/hack/src/typing/typing_env.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,14 @@ let get_static_member is_method env class_ mid =
816816

817817
ce_opt
818818

819-
(* Given a list of things whose name we can extract with `f`, return
820-
the item whose name is closest to `name`. *)
819+
(* Given a list of [possibilities] whose name we can extract with [f], return
820+
the item whose name is closest to [name]. *)
821821
let most_similar (name : string) (possibilities : 'a list) (f : 'a -> string) :
822822
'a option =
823+
(* Compare strings case-insensitively. *)
824+
let name = String.lowercase name in
825+
let f x = String.lowercase (f x) in
826+
823827
let distance upper_bound = String_utils.levenshtein_distance ~upper_bound in
824828
let choose_closest ~best:(best, best_distance) candidate =
825829
let candidate_distance = distance (best_distance + 1) (f candidate) name in
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?hh
2+
3+
enum class E: mixed {
4+
int car = 1;
5+
int CARROT = 42;
6+
}
7+
8+
function takes_label(HH\EnumClass\Label<E, int> $_): void {}
9+
10+
function call_it(): void {
11+
takes_label(#carrot);
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
File "class_missing_label_case.php", line 11, characters 15-21:
2+
Enum class `E` does not contain a label named `carrot`. (Typing[4394])
3+
File "class_missing_label_case.php", line 3, characters 12-12:
4+
`E` is defined here
5+
File "class_missing_label_case.php", line 5, characters 7-12:
6+
Did you mean `#CARROT`?
7+
File "class_missing_label_case.php", line 8, characters 41-41:
8+
This is why I expected an enum class label from `E`.

0 commit comments

Comments
 (0)