From e3daa15dbdb4a7ca4b1bc596846074b21d29fe38 Mon Sep 17 00:00:00 2001 From: Max Heiber Date: Fri, 28 Oct 2022 04:58:45 -0700 Subject: [PATCH] add wip tests for the interaction of traits and constants Summary: Show gaps in shape-like-dict analysis w.r.t. traits and constantss. Nonexhuastive demonstration of the limitations. T136213776 (low-priority) is to handle traits Reviewed By: madgen Differential Revision: D40714154 fbshipit-source-id: 0185b4a6da95f86f3cbef808510e79eaa622888b --- .../solve_constraints/trait_const_1_wip.php | 14 ++++++++++++++ .../solve_constraints/trait_const_1_wip.php.exp | 7 +++++++ .../solve_constraints/trait_const_2_wip.php | 17 +++++++++++++++++ .../solve_constraints/trait_const_2_wip.php.exp | 8 ++++++++ 4 files changed, 46 insertions(+) create mode 100644 hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php create mode 100644 hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php.exp create mode 100644 hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php create mode 100644 hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php.exp diff --git a/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php new file mode 100644 index 00000000000..0dca882ab35 --- /dev/null +++ b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php @@ -0,0 +1,14 @@ + DICT = dict[]; +} + +class TheClass { + use TheTrait; +} + +function main(): void { + TheClass::DICT['b']; +} diff --git a/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php.exp b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php.exp new file mode 100644 index 00000000000..b784bfcfaa6 --- /dev/null +++ b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php.exp @@ -0,0 +1,7 @@ +=== Shape analysis results for trait_const_1_wip.php +Summary after closing and simplifying for \TheTrait::DICT: +[5:9-28] [Constant]: + shape() +[5:36-42] [Allocation]: + shape() +Summary after closing and simplifying for \main: diff --git a/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php new file mode 100644 index 00000000000..5255fcc3992 --- /dev/null +++ b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php @@ -0,0 +1,17 @@ + DICT = dict["a" => "2"]; +} + +trait Childish { + require extends TheParent; + public static function foo(): void { + parent::DICT['b']; + } +} + +class Child extends TheParent { + use Childish; +} diff --git a/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php.exp b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php.exp new file mode 100644 index 00000000000..1f80966a910 --- /dev/null +++ b/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php.exp @@ -0,0 +1,8 @@ +=== Shape analysis results for trait_const_2_wip.php +Summary after closing and simplifying for \Child: +Summary after closing and simplifying for \Childish::foo: +Summary after closing and simplifying for \TheParent::DICT: +[5:11-31] [Constant]: + shape('a' => string) +[5:39-55] [Allocation]: + shape('a' => string) -- 2.11.4.GIT