Generate distinct error when indexing covariant containersnightly-2021.08.15nightly-2021.08.16
commit4005bae7a5105cfbc242e70dfdd5e016e1255611
authorMichael Thomas <mjt@fb.com>
Sat, 14 Aug 2021 22:45:46 +0000 (14 15:45 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Sat, 14 Aug 2021 22:47:07 +0000 (14 15:47 -0700)
treeac1f1962d50b0fc9b6a71590026a96c2aa63a7b6
parent9b30dcabef2506d15bb45d6a27ef3130baae0f94
Generate distinct error when indexing covariant containers

Summary:
D29663090 (https://github.com/facebook/hhvm/commit/6e901314e9bd74462f45cf59bcb4493e52c5ee59) modified the TAST check on containers with covariant in their keys to be consistent with the treatment in typing, i.e. it is only an error if the indexing expression cannot be types as `arraykey`. Whilst correct, this allows indexing of, for example, a `dict<string,_>` with an `int` which will always fail.

This diff restores the previous behaviour but uses a distinct error code, 4449, CovariantIndexTypeMismatch, which still allows us to discern this case from (castable) type errors.

Reviewed By: hgoldstein

Differential Revision: D30281788

fbshipit-source-id: ee0ca2ac34ead6eea9316d27bcfbb1bc5a5955fd
17 files changed:
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/oxidized/gen/error_codes.rs
hphp/hack/src/typing/tast_check/invalid_index_check.ml
hphp/hack/test/typecheck/array/array_get_covariant_key.php.exp
hphp/hack/test/typecheck/array/array_get_covariant_key.php.legacy_decl.exp [new file with mode: 0644]
hphp/hack/test/typecheck/array/array_get_covariant_key.php.like_types.exp
hphp/hack/test/typecheck/new_inference/eager_solve/array_get_bad.php.exp
hphp/hack/test/typecheck/new_inference/eager_solve/array_get_bad.php.legacy_decl.exp [new file with mode: 0644]
hphp/hack/test/typecheck/new_inference/eager_solve/array_get_bad.php.like_types.exp
hphp/hack/test/typecheck/new_inference/index_array_bad.php.exp
hphp/hack/test/typecheck/new_inference/index_array_bad.php.legacy_decl.exp [copied from hphp/hack/test/typecheck/new_inference/index_array_bad.php.exp with 83% similarity]
hphp/hack/test/typecheck/new_inference/index_array_bad.php.like_types.exp
hphp/hack/test/typecheck/unset_typechecks_arg.php.exp
hphp/hack/test/typecheck/unset_typechecks_arg.php.legacy_decl.exp [new file with mode: 0644]
hphp/hack/test/typecheck/unset_typechecks_arg.php.like_types.exp