Skip to content

Commit bebe707

Browse files
Wilfredfacebook-github-bot
authored andcommitted
Don't consider class name for similarity in naming errors
Summary: When we require a fully qualified label name `FooClass#bar_label`, we should only consider the `#bar_label` text in the similarity calculation. Previously, we'd suggest `FooClass#unrelated` as a match for `foo`, rather than `FooClass#foo`. Reviewed By: vsiles Differential Revision: D39329902 fbshipit-source-id: 15faf0d4f9c928e2b6fa7db40ab87f41847ecb8e
1 parent 3a3a5a5 commit bebe707

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

hphp/hack/src/typing/typing.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,14 +2065,18 @@ module EnumClassLabelOps = struct
20652065
Cls.consts cls
20662066
|> List.filter ~f:(fun (name, _) ->
20672067
not (String.equal name SN.Members.mClass))
2068-
|> List.map ~f:(fun (name, const) ->
2069-
( (if full then
2070-
Render.strip_ns enum_name ^ "#" ^ name
2071-
else
2072-
"#" ^ name),
2073-
const.cc_pos ))
20742068
in
2075-
let most_similar = Env.most_similar label_name consts fst in
2069+
let most_similar =
2070+
match Env.most_similar label_name consts fst with
2071+
| Some (name, const) ->
2072+
Some
2073+
( (if full then
2074+
Render.strip_ns enum_name ^ "#" ^ name
2075+
else
2076+
"#" ^ name),
2077+
const.cc_pos )
2078+
| None -> None
2079+
in
20762080
Errors.add_typing_error
20772081
Typing_error.(
20782082
enum
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?hh
2+
3+
enum class VeryLongClassName: mixed {
4+
int f = 1;
5+
int foobar = 1;
6+
}
7+
8+
function foo(): void {
9+
$x = VeryLongClassName#foobarr;
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
File "missing_label.php", line 9, characters 8-32:
2+
Enum class `VeryLongClassName` does not contain a label named `foobarr`. (Typing[4394])
3+
File "missing_label.php", line 3, characters 12-28:
4+
`VeryLongClassName` is defined here
5+
File "missing_label.php", line 5, characters 7-12:
6+
Did you mean `VeryLongClassName#foobar`?

0 commit comments

Comments
 (0)