Default to ~int in arithmetic ops
commit5993df11189143072886ccd6b7aaa19745f1ac47
authorAndrew Kennedy <akenn@fb.com>
Wed, 31 Aug 2022 13:34:09 +0000 (31 06:34 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 31 Aug 2022 13:34:09 +0000 (31 06:34 -0700)
tree578b8b301ec84e0a85a623d32140bf907a138888
parent6c95bdbe3b1ca9a5cb46e66fe46ba84c112b7aef
Default to ~int in arithmetic ops

Summary:
Arithmetic operations (such as unary negation, ++, etc), default to integer types if the operands have completely unknown types. Unfortunately this doesn't get preserved under `--pessimise-builtins` because we determine `is_like=true` for `~#0`, and allow `#0` to be solved to `nothing`. Instead, let's only do this if the type is literally `dynamic`.

Also use same code for inc/dec operations as for unary negation.

Differential Revision: D39052984

fbshipit-source-id: 4578a135be0596140d2b69ea0c04a968eb12f6f3
hphp/hack/src/typing/typing_arithmetic.ml
hphp/hack/test/sound_dynamic/typing/minus.good.php
hphp/hack/test/typecheck/arithmetic_default_types.php [new file with mode: 0644]
hphp/hack/test/typecheck/arithmetic_default_types.php.exp [new file with mode: 0644]