Skip to content

Commit 8658ff6

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
Eliminate intermediate flow provenance when reporting Arith_ret_[XXX] errors
Summary: Ensures that the claim for `Arith_ret_[XXX]` errors is the same under extended reasons by traversing to the first element of a flow appearing inside one of these reasons. Reviewed By: madgen Differential Revision: D63456760 fbshipit-source-id: 6eea7b60b7634e7046d4b688a0b37caec7033a4a
1 parent 4970bd7 commit 8658ff6

File tree

6 files changed

+6
-666
lines changed

6 files changed

+6
-666
lines changed

hphp/hack/src/typing/typing_reason.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,9 @@ let rec to_string : type a. string -> a t_ -> (Pos_or_decl.t * string) list =
21082108
| Arith_ret_float (_, r, s) ->
21092109
let rec find_last reason =
21102110
match reason with
2111-
| Arith_ret_float (_, r, _) -> find_last r
2111+
| Flow { from = r; _ }
2112+
| Arith_ret_float (_, r, _) ->
2113+
find_last r
21122114
| r -> r
21132115
in
21142116
let r_last = find_last r in
@@ -2125,7 +2127,9 @@ let rec to_string : type a. string -> a t_ -> (Pos_or_decl.t * string) list =
21252127
| Arith_ret_num (_, r, s) ->
21262128
let rec find_last reason =
21272129
match reason with
2128-
| Arith_ret_num (_, r, _) -> find_last r
2130+
| Flow { from = r; _ }
2131+
| Arith_ret_num (_, r, _) ->
2132+
find_last r
21292133
| r -> r
21302134
in
21312135
let r_last = find_last r in

hphp/hack/test/extended_reasons/num.php.debug.exp

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ error: Typing[4110] Invalid return type
22

33
File "num.php", line 9, character 10 - line 9, character 15:
44

5-
5 | $x = 5 + $x;
6-
6 | $x = $x + 5;
7-
7 | $x = 5 + $x;
85
8 | $x = 5 + $x;
96
9 | return »5 + $x«;
107
10 | }
@@ -16,82 +13,22 @@ File "num.php", line 3, character 23 - line 3, character 28:
1613
3 | function foo(num $n): »string« {
1714
4 | $x = 5 + $n;
1815
5 | $x = 5 + $x;
19-
6 | $x = $x + 5;
20-
7 | $x = 5 + $x;
2116

2217
But got `float` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
2318

2419
File "num.php", line 9, character 10 - line 9, character 15:
2520

26-
5 | $x = 5 + $x;
27-
6 | $x = $x + 5;
28-
7 | $x = 5 + $x;
2921
8 | $x = 5 + $x;
3022
9 | return »5 + $x«;
3123
10 | }
3224

33-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
34-
35-
File "num.php", line 8, character 8 - line 8, character 13:
36-
37-
5 | $x = 5 + $x;
38-
6 | $x = $x + 5;
39-
7 | $x = 5 + $x;
40-
8 | $x = »5 + $x«;
41-
9 | return 5 + $x;
42-
10 | }
43-
44-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
45-
46-
File "num.php", line 7, character 8 - line 7, character 13:
47-
48-
5 | $x = 5 + $x;
49-
6 | $x = $x + 5;
50-
7 | $x = »5 + $x«;
51-
8 | $x = 5 + $x;
52-
9 | return 5 + $x;
53-
10 | }
54-
55-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the first argument, and no `float`s.
56-
57-
File "num.php", line 6, character 8 - line 6, character 13:
58-
59-
5 | $x = 5 + $x;
60-
6 | $x = »$x + 5«;
61-
7 | $x = 5 + $x;
62-
8 | $x = 5 + $x;
63-
9 | return 5 + $x;
64-
10 | }
65-
66-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
67-
68-
File "num.php", line 5, character 8 - line 5, character 13:
69-
70-
3 | function foo(num $n): string {
71-
4 | $x = 5 + $n;
72-
5 | $x = »5 + $x«;
73-
6 | $x = $x + 5;
74-
7 | $x = 5 + $x;
75-
76-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
77-
78-
File "num.php", line 4, character 8 - line 4, character 13:
79-
80-
3 | function foo(num $n): string {
81-
4 | $x = »5 + $n«;
82-
5 | $x = 5 + $x;
83-
6 | $x = $x + 5;
84-
7 | $x = 5 + $x;
85-
8625
Here is why I think the argument is a `num`: this is a `num`
8726

8827
File "num.php", line 3, character 14 - line 3, character 16:
8928

9029
3 | function foo(»num« $n): string {
9130
4 | $x = 5 + $n;
9231
5 | $x = 5 + $x;
93-
6 | $x = $x + 5;
94-
7 | $x = 5 + $x;
9532

9633
Derivation:
9734
{
@@ -747,9 +684,6 @@ error: Typing[4110] Invalid return type
747684

748685
File "num.php", line 9, character 10 - line 9, character 15:
749686

750-
5 | $x = 5 + $x;
751-
6 | $x = $x + 5;
752-
7 | $x = 5 + $x;
753687
8 | $x = 5 + $x;
754688
9 | return »5 + $x«;
755689
10 | }
@@ -761,82 +695,22 @@ File "num.php", line 3, character 23 - line 3, character 28:
761695
3 | function foo(num $n): »string« {
762696
4 | $x = 5 + $n;
763697
5 | $x = 5 + $x;
764-
6 | $x = $x + 5;
765-
7 | $x = 5 + $x;
766698

767699
But got `int` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
768700

769701
File "num.php", line 9, character 10 - line 9, character 15:
770702

771-
5 | $x = 5 + $x;
772-
6 | $x = $x + 5;
773-
7 | $x = 5 + $x;
774703
8 | $x = 5 + $x;
775704
9 | return »5 + $x«;
776705
10 | }
777706

778-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
779-
780-
File "num.php", line 8, character 8 - line 8, character 13:
781-
782-
5 | $x = 5 + $x;
783-
6 | $x = $x + 5;
784-
7 | $x = 5 + $x;
785-
8 | $x = »5 + $x«;
786-
9 | return 5 + $x;
787-
10 | }
788-
789-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
790-
791-
File "num.php", line 7, character 8 - line 7, character 13:
792-
793-
5 | $x = 5 + $x;
794-
6 | $x = $x + 5;
795-
7 | $x = »5 + $x«;
796-
8 | $x = 5 + $x;
797-
9 | return 5 + $x;
798-
10 | }
799-
800-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the first argument, and no `float`s.
801-
802-
File "num.php", line 6, character 8 - line 6, character 13:
803-
804-
5 | $x = 5 + $x;
805-
6 | $x = »$x + 5«;
806-
7 | $x = 5 + $x;
807-
8 | $x = 5 + $x;
808-
9 | return 5 + $x;
809-
10 | }
810-
811-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
812-
813-
File "num.php", line 5, character 8 - line 5, character 13:
814-
815-
3 | function foo(num $n): string {
816-
4 | $x = 5 + $n;
817-
5 | $x = »5 + $x«;
818-
6 | $x = $x + 5;
819-
7 | $x = 5 + $x;
820-
821-
Here is why I think the argument is a `num`: this is a `num` because this is the result of an arithmetic operation with a `num` as the second argument, and no `float`s.
822-
823-
File "num.php", line 4, character 8 - line 4, character 13:
824-
825-
3 | function foo(num $n): string {
826-
4 | $x = »5 + $n«;
827-
5 | $x = 5 + $x;
828-
6 | $x = $x + 5;
829-
7 | $x = 5 + $x;
830-
831707
Here is why I think the argument is a `num`: this is a `num`
832708

833709
File "num.php", line 3, character 14 - line 3, character 16:
834710

835711
3 | function foo(»num« $n): string {
836712
4 | $x = 5 + $n;
837713
5 | $x = 5 + $x;
838-
6 | $x = $x + 5;
839-
7 | $x = 5 + $x;
840714

841715
Derivation:
842716
{

hphp/hack/test/extended_reasons/num.php.diff.exp

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)