Skip to content

Commit ede6355

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
Add test to exercise bug with invariant tyvars in return exprs
Summary: There is a bug which means we drop provenance when we have a return expression which contains an (unvolved) invariant type variable. This situation was missing in the test cases so this diff adds such a case. Reviewed By: madgen Differential Revision: D63749750 fbshipit-source-id: 71836fe38d4cd2c6197539464a0fa412eddf4943
1 parent 8658ff6 commit ede6355

File tree

6 files changed

+350
-0
lines changed

6 files changed

+350
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?hh
2+
3+
function foo(): Vector<int> {
4+
$x = Vector { 1 , '2' };
5+
$y = $x;
6+
$z = $y;
7+
// hh_force_solve();
8+
return $z;
9+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
error: Typing[4110] Invalid return type
2+
3+
File "vector_invariant.php", line 8, character 10 - line 8, character 11:
4+
5+
7 | // hh_force_solve();
6+
8 | return »$z«;
7+
9 | }
8+
9+
Expected `int`
10+
11+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
12+
13+
3 | function foo(): Vector<»int«> {
14+
4 | $x = Vector { 1 , '2' };
15+
5 | $y = $x;
16+
6 | $z = $y;
17+
18+
But got `string`
19+
20+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
21+
22+
3 | function foo(): Vector<int> {
23+
4 | $x = Vector { 1 , »'2'« };
24+
5 | $y = $x;
25+
6 | $z = $y;
26+
27+
Derivation:
28+
{
29+
"Lower":{
30+
"bound":{
31+
"Derivation":[
32+
{
33+
"Begin":{
34+
"sub":[
35+
{
36+
"Witness":[{"filename":"vector_invariant.php","line":4,"char_start":22,"char_end":24}]
37+
}
38+
],
39+
"super":[
40+
{
41+
"Type_variable_generics":[
42+
{"filename":"vector_invariant.php","line":4,"char_start":9,"char_end":26},
43+
"T",
44+
"HH\\Vector",
45+
"0"
46+
]
47+
}
48+
]
49+
}
50+
}
51+
]
52+
},
53+
"in_":{
54+
"Derivation":[
55+
{
56+
"Begin":{
57+
"sub":[
58+
{
59+
"Witness":[{"filename":"vector_invariant.php","line":4,"char_start":22,"char_end":24}]
60+
}
61+
],
62+
"super":[
63+
{
64+
"Hint":[{"filename":"vector_invariant.php","line":3,"char_start":24,"char_end":26}]
65+
}
66+
]
67+
}
68+
}
69+
]
70+
}
71+
}
72+
}
73+
74+
File "", line 0, character 0 - line 0, character -1:
75+
76+
77+
Reason:
78+
{
79+
"Subtype":{
80+
"sub":[
81+
{
82+
"Lower_bound":{
83+
"bound":[
84+
{
85+
"Witness":[{"filename":"vector_invariant.php","line":4,"char_start":22,"char_end":24}]
86+
}
87+
],
88+
"of":[
89+
{
90+
"Type_variable_generics":[
91+
{"filename":"vector_invariant.php","line":4,"char_start":9,"char_end":26},
92+
"T",
93+
"HH\\Vector",
94+
"0"
95+
]
96+
}
97+
]
98+
}
99+
}
100+
],
101+
"super":[
102+
{
103+
"Hint":[{"filename":"vector_invariant.php","line":3,"char_start":24,"char_end":26}]
104+
}
105+
]
106+
}
107+
}
108+
109+
File "", line 0, character 0 - line 0, character -1:
110+
111+
112+
1 error found
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- control
2+
3+
+++ test
4+
5+
@@ -1,6 +1,5 @@
6+
7+
error: Typing[4110] Invalid return type [1]
8+
-> Expected int [2]
9+
--> This type argument to Vector must match exactly (it is invariant) [2]
10+
-> But got string [3]
11+
12+
hphp/hack/test/extended_reasons/vector_invariant.php:8:10
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
error: Typing[4110] Invalid return type
2+
3+
File "vector_invariant.php", line 8, character 10 - line 8, character 11:
4+
5+
7 | // hh_force_solve();
6+
8 | return »$z«;
7+
9 | }
8+
9+
Expected `int`
10+
11+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
12+
13+
3 | function foo(): Vector<»int«> {
14+
4 | $x = Vector { 1 , '2' };
15+
5 | $y = $x;
16+
6 | $z = $y;
17+
18+
But got `string`
19+
20+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
21+
22+
3 | function foo(): Vector<int> {
23+
4 | $x = Vector { 1 , »'2'« };
24+
5 | $y = $x;
25+
6 | $z = $y;
26+
27+
Here's why:
28+
29+
I checked the subtype constraint in [Main] because it was implied by transitivity.
30+
31+
Main
32+
33+
[Main] Step 1 of 1 (here is where the error occurred)
34+
35+
I started by checking this subtype relationship.
36+
37+
The subtype comes from this expression
38+
39+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
40+
41+
3 | function foo(): Vector<int> {
42+
4 | $x = Vector { 1 , »'2'« };
43+
5 | $y = $x;
44+
6 | $z = $y;
45+
46+
The supertype comes from this hint
47+
48+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
49+
50+
3 | function foo(): Vector<»int«> {
51+
4 | $x = Vector { 1 , '2' };
52+
5 | $y = $x;
53+
6 | $z = $y;
54+
55+
I found the subtype for [Main] is when I checked the subtype constraint in [Lower].
56+
57+
Lower
58+
59+
[Lower] Step 1 of 1
60+
61+
I started by checking this subtype relationship.
62+
63+
The subtype comes from this expression
64+
65+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
66+
67+
3 | function foo(): Vector<int> {
68+
4 | $x = Vector { 1 , »'2'« };
69+
5 | $y = $x;
70+
6 | $z = $y;
71+
72+
The supertype comes from this generic parameter `T` of `HH\Vector`
73+
74+
File "vector_invariant.php", line 4, character 9 - line 4, character 26:
75+
76+
3 | function foo(): Vector<int> {
77+
4 | $x = »Vector { 1 , '2' }«;
78+
5 | $y = $x;
79+
6 | $z = $y;
80+
81+
1 error found
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: Typing[4110] Invalid return type
2+
3+
File "vector_invariant.php", line 8, character 10 - line 8, character 11:
4+
5+
7 | // hh_force_solve();
6+
8 | return »$z«;
7+
9 | }
8+
9+
Expected `int`
10+
11+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
12+
13+
3 | function foo(): Vector<»int«> {
14+
4 | $x = Vector { 1 , '2' };
15+
5 | $y = $x;
16+
6 | $z = $y;
17+
18+
But got `string`
19+
20+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
21+
22+
3 | function foo(): Vector<int> {
23+
4 | $x = Vector { 1 , »'2'« };
24+
5 | $y = $x;
25+
6 | $z = $y;
26+
27+
Here's why:
28+
29+
I checked the subtype constraint in [Main] because it was implied by transitivity.
30+
31+
Main
32+
33+
[Main] Step 1 of 1 (here is where the error occurred)
34+
35+
I started by checking this subtype relationship.
36+
37+
The subtype comes from this expression
38+
39+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
40+
41+
3 | function foo(): Vector<int> {
42+
4 | $x = Vector { 1 , »'2'« };
43+
5 | $y = $x;
44+
6 | $z = $y;
45+
46+
The supertype comes from this hint
47+
48+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
49+
50+
3 | function foo(): Vector<»int«> {
51+
4 | $x = Vector { 1 , '2' };
52+
5 | $y = $x;
53+
6 | $z = $y;
54+
55+
1 error found
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
error: Typing[4110] Invalid return type
2+
3+
File "vector_invariant.php", line 8, character 10 - line 8, character 11:
4+
5+
7 | // hh_force_solve();
6+
8 | return »$z«;
7+
9 | }
8+
9+
Expected `int`
10+
11+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
12+
13+
3 | function foo(): Vector<»int«> {
14+
4 | $x = Vector { 1 , '2' };
15+
5 | $y = $x;
16+
6 | $z = $y;
17+
18+
But got `string`
19+
20+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
21+
22+
3 | function foo(): Vector<int> {
23+
4 | $x = Vector { 1 , »'2'« };
24+
5 | $y = $x;
25+
6 | $z = $y;
26+
27+
Here's why:
28+
29+
I checked the subtype constraint in [Main] because it was implied by transitivity.
30+
31+
Main
32+
33+
[Main] Step 1 of 1 (here is where the error occurred)
34+
35+
I started by checking this subtype relationship.
36+
37+
The subtype comes from this expression
38+
39+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
40+
41+
3 | function foo(): Vector<int> {
42+
4 | $x = Vector { 1 , »'2'« };
43+
5 | $y = $x;
44+
6 | $z = $y;
45+
46+
The supertype comes from this hint
47+
48+
File "vector_invariant.php", line 3, character 24 - line 3, character 26:
49+
50+
3 | function foo(): Vector<»int«> {
51+
4 | $x = Vector { 1 , '2' };
52+
5 | $y = $x;
53+
6 | $z = $y;
54+
55+
I found the subtype for [Main] is when I checked the subtype constraint in [Lower].
56+
57+
Lower
58+
59+
[Lower] Step 1 of 1
60+
61+
I started by checking this subtype relationship.
62+
63+
The subtype comes from this expression
64+
65+
File "vector_invariant.php", line 4, character 22 - line 4, character 24:
66+
67+
3 | function foo(): Vector<int> {
68+
4 | $x = Vector { 1 , »'2'« };
69+
5 | $y = $x;
70+
6 | $z = $y;
71+
72+
The supertype comes from this generic parameter `T` of `HH\Vector`
73+
74+
File "vector_invariant.php", line 4, character 9 - line 4, character 26:
75+
76+
3 | function foo(): Vector<int> {
77+
4 | $x = »Vector { 1 , '2' }«;
78+
5 | $y = $x;
79+
6 | $z = $y;
80+
81+
1 error found

0 commit comments

Comments
 (0)