Skip to content

Commit

Permalink
Pretty-printing: show constraints on type parameters inside newtypes …
Browse files Browse the repository at this point in the history
…and dependent types

Summary: For unknown reasons, we don't look inside `newtype` arguments or dependent types when presenting bounds on generic parameters in pretty printed types. Unfortunately, this affects `supportdyn<_>` types such as function types under implicit pessimisation. Let's get rid of this filtering.

Reviewed By: madgen

Differential Revision: D63023172

fbshipit-source-id: f5ea603734cf13f84a22ca2d4f4fb59383427ce2
  • Loading branch information
Andrew Kennedy authored and facebook-github-bot committed Sep 19, 2024
1 parent 812d981 commit 362a384
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 18 deletions.
9 changes: 1 addition & 8 deletions hphp/hack/src/typing/typing_env_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,9 @@ let get_tparams_in_ty_and_acc env acc ty =
inherit [SSet.t] Type_visitor.locl_type_visitor

method! on_tgeneric acc _ s _ =
(* as for tnewtype: not traversing args, although they may contain Tgenerics *)
(* Not traversing args, although they may contain Tgenerics (higher kinds only) *)
SSet.add s acc

(* Perserving behavior but this seems incorrect to me since a newtype may
* contain type arguments with generics
*)
method! on_tdependent acc _ _ _ = acc

method! on_tnewtype acc _ _ _ _ = acc

method! on_tvar acc r ix =
let (_env, ty) =
Typing_inference_env.expand_var env.inference_env r ix
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/bad_type_structure_class.php.exp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ File "bad_type_structure_class.php", line 25, characters 3-23:
File "bad_type_structure_class.php", line 26, characters 3-22:
?string
File "bad_type_structure_class.php", line 27, characters 3-27:
classname<T>
classname<T> where T as C<int>
File "bad_type_structure_class.php", line 28, characters 3-31:
?vec<mixed>
File "bad_type_structure_class.php", line 31, characters 3-26:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/classname/classname_usage.php.exp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "classname_usage.php", line 81, characters 3-15:
string
File "classname_usage.php", line 86, characters 3-16:
classname<T>
classname<T> where T as I
File "classname_usage.php", line 88, characters 3-15:
string
No errors
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "classname_usage.php", line 81, characters 3-15:
~string
File "classname_usage.php", line 86, characters 3-16:
classname<T>
classname<T> where T as I
File "classname_usage.php", line 88, characters 3-15:
~string
No errors
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/classname/new.php.imp_pess_exp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ File "new.php", line 24, characters 3-16:
File "new.php", line 30, characters 3-16:
Td as D<I>
File "new.php", line 47, characters 5-18:
~<expr#5> as T
~<expr#5> as T where T as C
ERROR: File "new.php", line 17, characters 15-20:
Can't use `new` on `classname<I>`; `__construct` arguments are not guaranteed to be consistent in child classes (Typing[4060])
File "new.php", line 16, characters 25-25:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/lambda/lambda16.php.imp_pess_exp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Invalid return type (Typing[4110])
File "lambda16.php", line 13, characters 30-33:
Expected `this`
File "lambda16.php", line 14, characters 12-23:
But got `(function(): this)`
But got `(function(): this) where this as Foo<T>`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "type_structure_abstract.php", line 10, characters 5-73:
?classname<this::T>
?classname<this::T> where this::T as P::T
File "type_structure_abstract.php", line 17, characters 5-60:
classname<this::T>
classname<this::T> where this::T as C::T
File "type_structure_abstract.php", line 24, characters 5-60:
classname<IChild>
No errors
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ File "typing_type_structure1.php", line 25, characters 5-30:
File "typing_type_structure1.php", line 26, characters 5-30:
(TypeStructure<Vector<C<int>>>)
File "typing_type_structure1.php", line 27, characters 5-28:
classname<this>
classname<this> where this as D
No errors
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ File "typing_type_structure1.php", line 25, characters 5-30:
File "typing_type_structure1.php", line 26, characters 5-30:
(TypeStructure<~Vector<C<int>>>)
File "typing_type_structure1.php", line 27, characters 5-28:
classname<this>
classname<this> where this as D
No errors
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "typing_type_structure2.php", line 13, characters 5-28:
classname<this>
classname<this> where this as C
File "typing_type_structure2.php", line 14, characters 5-28:
classname<Base>
No errors

0 comments on commit 362a384

Please sign in to comment.