Fix unsoundness bug with arithmetic and unresolved types
commita61ae333768ef892edecf6a95cf050de5caac7c4
authorAndrew Kennedy <akenn@fb.com>
Thu, 4 Jul 2019 12:06:43 +0000 (4 05:06 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Thu, 4 Jul 2019 12:10:23 +0000 (4 05:10 -0700)
tree81b54e7c05eb457fe4d53ac731c5edb2a41a3c23
parentb44d22033f69c6c770d746c6480669cb823ab254
Fix unsoundness bug with arithmetic and unresolved types

Summary:
Arithmetic is broken wrt unresolved-type arguments. For example, Hack thinks that
```
$x ==> $x + 1
```
has type `function(num):int` if the lambda is passed to a generic function.

To fix this, we revamp the type checker code for arithmetic, using `expand_type_and_narrow` to use the lower bound if possible, defaulting to `int`.

The original bug was due to `is_sub_type_LEGACY_DEPRECATED` returning `true` for type variables (e.g. a test of `#1 <: int` would return `true`).

Reviewed By: CatherineGasnier

Differential Revision: D15780423

fbshipit-source-id: d1e68e7cc633c6f3a7f15b3e6f195f04d828c4e7
31 files changed:
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_async.ml
hphp/hack/src/typing/typing_subtype.ml
hphp/hack/src/typing/typing_subtype.mli
hphp/hack/test/typecheck/add_union_any.php [new file with mode: 0644]
hphp/hack/test/typecheck/add_union_any.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/anon2.php.exp
hphp/hack/test/typecheck/arithmetic_enum.php [new file with mode: 0644]
hphp/hack/test/typecheck/arithmetic_enum.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/arithmetic_lower.php [new file with mode: 0644]
hphp/hack/test/typecheck/arithmetic_lower.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/dynamic/dynamic_arithmetic.php [new file with mode: 0644]
hphp/hack/test/typecheck/dynamic/dynamic_arithmetic.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/HH_FLAGS
hphp/hack/test/typecheck/lambda/decl_lambda_hints.php
hphp/hack/test/typecheck/lambda/expected_float.php [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/expected_float.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/foreach_map_float.php [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/foreach_map_float.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_apply.php.exp
hphp/hack/test/typecheck/lambda/lambda_arithmetic_bad.php [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_arithmetic_bad.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_arithmetic_good.php [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_arithmetic_good.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_bad_arity.php.exp
hphp/hack/test/typecheck/lambda/lambda_bad_arity2.php.exp
hphp/hack/test/typecheck/lambda/lambda_hof_bad.php.exp
hphp/hack/test/typecheck/lambda/lambda_reduce.php [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/lambda_reduce.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/lambda/new_map_lambda.php.exp
hphp/hack/test/typecheck/lambda/variadics/inferred_variadic_type.php.exp