Skip to content

Commit d575a67

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
Report position of type parameter rather than function type
Summary: The `reified_check` currently uses the function position as the `decl_pos` when reporting that an argument must be given because it is declared `reify`. In the typing of function pointers to methods, the function position will actually be the expression location so this diff updates the reporting to give the position of the first type parameter that is declared `reify` instead. Reviewed By: andrewjkennedy Differential Revision: D74658684 fbshipit-source-id: 4d4c7420c2f8b5c168d39d1ff89c6a00128ea367
1 parent ed2d793 commit d575a67

21 files changed

+47
-27
lines changed

hphp/hack/src/typing/tast_check/reified_check.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ let verify_call_targs ?special_code env expr_pos decl_pos tparams targs =
152152
let targs_length = List.length targs in
153153
if Int.( <> ) tparams_length targs_length then
154154
if Int.( = ) targs_length 0 then
155+
let decl_pos =
156+
Option.value
157+
~default:decl_pos
158+
(List.find_map tparams ~f:(fun tparam ->
159+
if is_reified tparam then
160+
let Typing_defs_core.{ tp_name = (pos, _); _ } = tparam in
161+
Some pos
162+
else
163+
None))
164+
in
155165
Typing_error_utils.add_typing_error
156166
~env:(Tast_env.tast_env_as_typing_env env)
157167
Typing_error.(
@@ -164,6 +174,16 @@ let verify_call_targs ?special_code env expr_pos decl_pos tparams targs =
164174
List.for_all ~f:(fun (_, h) -> Aast_defs.is_wildcard_hint h) targs
165175
in
166176
if all_wildcards && tparams_has_reified tparams then
177+
let decl_pos =
178+
Option.value
179+
~default:decl_pos
180+
(List.find_map tparams ~f:(fun tparam ->
181+
if is_reified tparam then
182+
let Typing_defs_core.{ tp_name = (pos, _); _ } = tparam in
183+
Some pos
184+
else
185+
None))
186+
in
167187
Typing_error_utils.add_typing_error
168188
~env:(Tast_env.tast_env_as_typing_env env)
169189
Typing_error.(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ERROR: File "class_meth_reified.php", line 8, characters 3-12:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_meth_reified.php", line 4, characters 26-28:
3+
File "class_meth_reified.php", line 4, characters 36-36:
44
Definition is here
55
ERROR: File "class_meth_reified.php", line 10, characters 3-12:
66
All type arguments must be specified because a type parameter is reified (Typing[4303])
7-
File "class_meth_reified.php", line 4, characters 26-28:
7+
File "class_meth_reified.php", line 4, characters 36-36:
88
Definition is here
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ERROR: File "class_meth_reified_self.php", line 7, characters 5-15:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_meth_reified_self.php", line 4, characters 26-28:
3+
File "class_meth_reified_self.php", line 4, characters 36-36:
44
Definition is here
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ERROR: File "class_meth_reified_static.php", line 7, characters 5-17:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_meth_reified_static.php", line 4, characters 26-28:
3+
File "class_meth_reified_static.php", line 4, characters 36-36:
44
Definition is here
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ERROR: File "class_meth_reified_targs_missing.php", line 8, characters 8-17:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_meth_reified_targs_missing.php", line 4, characters 26-28:
3+
File "class_meth_reified_targs_missing.php", line 4, characters 36-36:
44
Definition is here
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ERROR: File "class_meth_reified_trait.php", line 8, characters 3-12:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_meth_reified_trait.php", line 4, characters 26-28:
3+
File "class_meth_reified_trait.php", line 4, characters 36-36:
44
Definition is here
55
ERROR: File "class_meth_reified_trait.php", line 10, characters 3-12:
66
All type arguments must be specified because a type parameter is reified (Typing[4303])
7-
File "class_meth_reified_trait.php", line 4, characters 26-28:
7+
File "class_meth_reified_trait.php", line 4, characters 36-36:
88
Definition is here
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ERROR: File "reified_fun.php", line 6, characters 3-7:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "reified_fun.php", line 6, characters 3-7:
3+
File "reified_fun.php", line 3, characters 20-20:
44
Definition is here
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ERROR: File "reified_targs_missing.php", line 7, characters 8-12:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "reified_targs_missing.php", line 7, characters 8-12:
3+
File "reified_targs_missing.php", line 3, characters 20-20:
44
Definition is here

hphp/hack/test/typecheck/generics_restrictions/explicit_reify_static_methods.php.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Illegal wildcard (`_`): generic type parameter `TF` must be specified explicitly
2626
Definition is here
2727
ERROR: File "explicit_reify_static_methods.php", line 32, characters 3-14:
2828
All type arguments must be specified because a type parameter is reified (Typing[4303])
29-
File "explicit_reify_static_methods.php", line 13, characters 26-32:
29+
File "explicit_reify_static_methods.php", line 13, characters 40-41:
3030
Definition is here
3131
ERROR: File "explicit_reify_static_methods.php", line 34, characters 3-17:
3232
All type arguments must be specified because a type parameter is reified (Typing[4303])
33-
File "explicit_reify_static_methods.php", line 13, characters 26-32:
33+
File "explicit_reify_static_methods.php", line 13, characters 40-41:
3434
Definition is here

hphp/hack/test/typecheck/reified_generics/class_soft_reification.php.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ERROR: File "class_soft_reification.php", line 12, characters 3-19:
22
All type arguments must be specified because a type parameter is reified (Typing[4303])
3-
File "class_soft_reification.php", line 5, characters 7-17:
3+
File "class_soft_reification.php", line 5, characters 36-36:
44
Definition is here
55
ERROR: File "class_soft_reification.php", line 15, characters 3-15:
66
All type arguments must be specified because a type parameter is reified (Typing[4303])
7-
File "class_soft_reification.php", line 6, characters 7-13:
7+
File "class_soft_reification.php", line 6, characters 21-21:
88
Definition is here
99
ERROR: File "class_soft_reification.php", line 28, characters 19-24:
1010
Invalid reified hint (Typing[4305])

0 commit comments

Comments
 (0)