Add subtyping for vec_or_dict
commit99c674fe26f6e1dc92f508a4ba9ea2a6e24d2eb3
authorVassil Mladenov <vmladenov@fb.com>
Thu, 11 Feb 2021 08:08:18 +0000 (11 00:08 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 11 Feb 2021 08:10:39 +0000 (11 00:10 -0800)
treea2198b74268861696004fcf336ef4610d5a87b22
parent9dcc664cd19d71c849be8ce052b11175d275c331
Add subtyping for vec_or_dict

Summary:
Adds the following subtyping rules, presented without contexts for brevity. Note that unlike in a type hint position, the *type* representing `vec_or_dict` always has two type parameters

```
  int <: tk         t <: tv
=============================
vec<t> <: vec_or_dict<tk, tv>

  tk1 <: tk2               tv1 <: tv2
=======================================
dict<tk1, tv1> <: vec_or_dict<tk2, tv2>

// the following rules just mimic the behavior for varray_or_darray

    tk1 <: tk2                          tv1 <: tv2
======================================================
vec_or_dict<tk1, tv1> <: vec_or_dict        <tk2, tv2>
                      <: KeyedTraversable   <tk2, tv2>
                      <: Rx\KeyedTraversable<tk2, tv2>
                      <: KeyedContainer     <tk2, tv2>
                      <: AnyArray           <tk2, tv2>

                  tv1 <: tv2
============================================
vec_or_dict<_tk, tv1> <: Traversable   <tv2>
                      <: Rx\Traversable<tv2>
                      <: Container     <tv2>

```

Differential Revision: D26333218

fbshipit-source-id: 4f1f40e28090173060a528142d88d69985e3f3e3
hphp/hack/src/typing/typing_subtype.ml
hphp/hack/test/typecheck/vec_or_dict1.php [new file with mode: 0644]
hphp/hack/test/typecheck/vec_or_dict1.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/vec_or_dict2.php [new file with mode: 0644]
hphp/hack/test/typecheck/vec_or_dict2.php.exp [new file with mode: 0644]