Skip to content

Commit 1532063

Browse files
Andrew Kennedyfacebook-github-bot
authored andcommitted
Preserve outcome of localization when checking splat well-formedness
Summary: We were dropping the environment on the floor when localizing a type `t` before checking that `...t` is well-formed i.e. that `t <: (mixed...)`. Unfortunately, localization *can* update the environment when resolving type constant projection, and this needs to be preserved before calling subtyping. Reviewed By: enetsee Differential Revision: D75450819 fbshipit-source-id: c045eb7c916209d30ae2a5afb89ac7f27febaace
1 parent 19a6722 commit 1532063

File tree

4 files changed

+133
-2
lines changed

4 files changed

+133
-2
lines changed

hphp/hack/src/typing/typing_type_wellformedness.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ let check_happly unchecked_tparams env h =
130130
env
131131

132132
let check_splat_hint env p h =
133-
let (_env, hint_pos, locl_ty) =
133+
(* It's important that we pass tenv down to subtyping
134+
* because tpenv might have been updated during localization *)
135+
let (tenv, hint_pos, locl_ty) =
134136
loclty_of_hint env.typedef_tparams env.tenv h
135137
in
136138
(* The top tuple (mixed...) *)
@@ -150,7 +152,7 @@ let check_splat_hint env p h =
150152
in
151153
let (_env, err) =
152154
Typing_generic_constraint.check_tparams_constraint
153-
env.tenv
155+
tenv
154156
~use_pos:hint_pos
155157
Ast_defs.Constraint_as
156158
~cstr_ty
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?hh
2+
3+
<<file: __EnableUnstableFeatures('type_splat', 'open_tuples')>>
4+
5+
class Other<T as (mixed...)> { }
6+
7+
abstract class Good {
8+
abstract const type TInputs as (arraykey...);
9+
10+
public function test1((function(...this::TInputs): void) $x):void { }
11+
public function test2(...this::TInputs $args):void { }
12+
public function test3(Other<this::TInputs> $a):void { }
13+
}
14+
15+
abstract class Bad {
16+
abstract const type TInputs;
17+
18+
public function test1((function(...this::TInputs): void) $x):void { }
19+
public function test2(...this::TInputs $args):void { }
20+
public function test3(Other<this::TInputs> $a):void { }
21+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
2+
Some type arguments violate their constraints (Typing[4323])
3+
File "type_splat_typeconst.php", line 18, characters 25-58:
4+
Expected `(mixed...)`
5+
File "type_splat_typeconst.php", line 18, characters 38-50:
6+
But got `this::TInputs`
7+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
8+
Some type arguments violate their constraints (Typing[4323])
9+
File "type_splat_typeconst.php", line 18, characters 25-58:
10+
Expected `(mixed...)`
11+
File "type_splat_typeconst.php", line 18, characters 44-50:
12+
But got `Bad::TInputs`
13+
by accessing the type constant `TInputs`
14+
File "type_splat_typeconst.php", line 18, characters 38-50:
15+
on the expression dependent type this
16+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
17+
Some type arguments violate their constraints (Typing[4323])
18+
File "type_splat_typeconst.php", line 18, characters 25-58:
19+
Expected `(mixed...)`
20+
File "type_splat_typeconst.php", line 18, characters 44-50:
21+
But got `mixed` arising from an implicit `as mixed` constraint on this type
22+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
23+
Some type arguments violate their constraints (Typing[4323])
24+
File "type_splat_typeconst.php", line 5, characters 13-13:
25+
`T` is a constrained type parameter
26+
File "type_splat_typeconst.php", line 5, characters 18-27:
27+
This type constraint is violated
28+
File "type_splat_typeconst.php", line 5, characters 18-27:
29+
Expected `(mixed...)`
30+
File "type_splat_typeconst.php", line 20, characters 31-43:
31+
But got `this::TInputs as Bad::TInputs`
32+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
33+
Some type arguments violate their constraints (Typing[4323])
34+
File "type_splat_typeconst.php", line 5, characters 13-13:
35+
`T` is a constrained type parameter
36+
File "type_splat_typeconst.php", line 5, characters 18-27:
37+
This type constraint is violated
38+
File "type_splat_typeconst.php", line 5, characters 18-27:
39+
Expected `(mixed...)`
40+
File "type_splat_typeconst.php", line 20, characters 37-43:
41+
But got `Bad::TInputs super this::TInputs`
42+
by accessing the type constant `TInputs`
43+
File "type_splat_typeconst.php", line 20, characters 31-43:
44+
on the expression dependent type this
45+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
46+
Some type arguments violate their constraints (Typing[4323])
47+
File "type_splat_typeconst.php", line 5, characters 13-13:
48+
`T` is a constrained type parameter
49+
File "type_splat_typeconst.php", line 5, characters 18-27:
50+
This type constraint is violated
51+
File "type_splat_typeconst.php", line 5, characters 18-27:
52+
Expected `(mixed...)`
53+
File "type_splat_typeconst.php", line 20, characters 37-43:
54+
But got `mixed` arising from an implicit `as mixed` constraint on this type
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
2+
Some type arguments violate their constraints (Typing[4323])
3+
File "type_splat_typeconst.php", line 18, characters 25-58:
4+
Expected `(mixed...)`
5+
File "type_splat_typeconst.php", line 16, characters 23-29:
6+
But got `mixed`
7+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
8+
Some type arguments violate their constraints (Typing[4323])
9+
File "type_splat_typeconst.php", line 18, characters 25-58:
10+
Expected `(mixed...)`
11+
File "type_splat_typeconst.php", line 18, characters 38-50:
12+
But got `this::TInputs`
13+
ERROR: File "type_splat_typeconst.php", line 18, characters 38-50:
14+
Some type arguments violate their constraints (Typing[4323])
15+
File "type_splat_typeconst.php", line 18, characters 25-58:
16+
Expected `(mixed...)`
17+
File "type_splat_typeconst.php", line 18, characters 44-50:
18+
But got `Bad::TInputs`
19+
by accessing the type constant `TInputs`
20+
File "type_splat_typeconst.php", line 18, characters 38-50:
21+
on the expression dependent type this
22+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
23+
Some type arguments violate their constraints (Typing[4323])
24+
File "type_splat_typeconst.php", line 5, characters 13-13:
25+
`T` is a constrained type parameter
26+
File "type_splat_typeconst.php", line 5, characters 18-27:
27+
This type constraint is violated
28+
File "type_splat_typeconst.php", line 5, characters 18-27:
29+
Expected `(mixed...)`
30+
File "type_splat_typeconst.php", line 16, characters 23-29:
31+
But got `mixed`
32+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
33+
Some type arguments violate their constraints (Typing[4323])
34+
File "type_splat_typeconst.php", line 5, characters 13-13:
35+
`T` is a constrained type parameter
36+
File "type_splat_typeconst.php", line 5, characters 18-27:
37+
This type constraint is violated
38+
File "type_splat_typeconst.php", line 5, characters 18-27:
39+
Expected `(mixed...)`
40+
File "type_splat_typeconst.php", line 20, characters 31-43:
41+
But got `this::TInputs as Bad::TInputs`
42+
ERROR: File "type_splat_typeconst.php", line 20, characters 25-44:
43+
Some type arguments violate their constraints (Typing[4323])
44+
File "type_splat_typeconst.php", line 5, characters 13-13:
45+
`T` is a constrained type parameter
46+
File "type_splat_typeconst.php", line 5, characters 18-27:
47+
This type constraint is violated
48+
File "type_splat_typeconst.php", line 5, characters 18-27:
49+
Expected `(mixed...)`
50+
File "type_splat_typeconst.php", line 20, characters 37-43:
51+
But got `Bad::TInputs super this::TInputs`
52+
by accessing the type constant `TInputs`
53+
File "type_splat_typeconst.php", line 20, characters 31-43:
54+
on the expression dependent type this

0 commit comments

Comments
 (0)