Correctly handle enum merging during unit loading.
commitd1274508fa8b40cc8b92eeeef57177ea888061fd
authorAlexey Toptygin <alexeyt@fb.com>
Tue, 2 Aug 2022 08:04:42 +0000 (2 01:04 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 2 Aug 2022 08:04:42 +0000 (2 01:04 -0700)
treeb19a2ebcaf4fc095947efb5ab64fb5ea2ac07738
parent4d180e1d4d71161a3ea18605d11b8a8a4c7835df
Correctly handle enum merging during unit loading.

Summary:
The logic in Class::def that was trying to prevent fatals during the !failIsFatal phase incorrectly encoded the rules for valid enum base type constraints (differing from the logic in Class::setEnumType), so enums would never get loaded in this phase unless their base type resolved to exactly int or string. This meant that out-of-order enum declarations in the same unit would fail to load if their base type was not exactly int or string.

Factor this code out into a helper in TypeConstraint, and make both Class::setEnumType and Class::def use the helper. This should prevent this type of bug in the future. Add a unit test.

Reviewed By: ricklavoie

Differential Revision: D38329638

fbshipit-source-id: 501e13487f9adecd40f68466e53e020ad5fec2b9
hphp/runtime/vm/class.cpp
hphp/runtime/vm/type-constraint.h
hphp/test/slow/enum-load-order.php [new file with mode: 0644]
hphp/test/slow/enum-load-order.php.expect [new file with mode: 0644]