From 74e198bad83ccaa1c5a147c24f1aeaf8acd97aaa Mon Sep 17 00:00:00 2001 From: David Snider Date: Thu, 23 Jul 2020 12:50:06 -0700 Subject: [PATCH] Set return type enforcement to be unrecoverable Summary: To ensure that removing the gating doesn't completely break OSS Reviewed By: fredemmott Differential Revision: D22637778 fbshipit-source-id: 8c9b514d1278f4d220c77a692deeeb0d939f9235 --- hphp/runtime/base/runtime-option.h | 2 +- hphp/test/quick/dict/type-hint.php | 94 +++++++++++++++++----------- hphp/test/quick/dict/type-hint.php.hphp_opts | 2 +- hphp/test/quick/keyset/type-hint.php | 79 ++++++++++++++--------- hphp/test/quick/vec/type-hint.php | 87 +++++++++++++++---------- 5 files changed, 166 insertions(+), 98 deletions(-) diff --git a/hphp/runtime/base/runtime-option.h b/hphp/runtime/base/runtime-option.h index b18d5f9230d..f2607052dfa 100644 --- a/hphp/runtime/base/runtime-option.h +++ b/hphp/runtime/base/runtime-option.h @@ -743,7 +743,7 @@ struct RuntimeOption { will not allow execution to resume normally; if the user error handler returns something other than boolean false, the runtime will throw a fatal error. */ \ - F(int32_t, CheckReturnTypeHints, 2) \ + F(int32_t, CheckReturnTypeHints, 3) \ /* CheckPropTypeHints: 0 - No checks or enforcement of property type hints. diff --git a/hphp/test/quick/dict/type-hint.php b/hphp/test/quick/dict/type-hint.php index b40f51e21f6..7acb0db27f9 100644 --- a/hphp/test/quick/dict/type-hint.php +++ b/hphp/test/quick/dict/type-hint.php @@ -85,47 +85,66 @@ function takes_vec_or_dict3(<<__Soft>> vec_or_dict $x): vec_or_dict { function test_all_hints($x) { echo "====================================================\n"; var_dump($x); - takes_dict1($x) - |> takes_dict2($$) - |> takes_dict3($$) - |> takes_dict4($$) - |> takes_dict5($$) - |> takes_container1($$) - |> takes_container2($$) - |> takes_keyed_container($$) - |> takes_traversable($$) - |> takes_keyed_traversable($$) - |> takes_vec($$) - |> takes_keyset($$) - |> takes_array1($$) - |> takes_array2($$) - |> takes_bool($$) - |> takes_string($$) - |> takes_xhp_child($$) - |> takes_foo($$) - |> takes_vector_container($$) - |> takes_map_container($$) - |> takes_null($$) - |> takes_nonnull($$) - |> takes_mixed($$) - |> takes_vec_or_dict1($$) - |> takes_vec_or_dict2($$) - |> takes_vec_or_dict3($$) - |> var_dump($$); + $funs = vec[ + 'takes_dict1', + 'takes_dict2', + 'takes_dict3', + 'takes_dict4', + 'takes_dict5', + 'takes_container1', + 'takes_container2', + 'takes_keyed_container', + 'takes_traversable', + 'takes_keyed_traversable', + 'takes_vec', + 'takes_keyset', + 'takes_array1', + 'takes_array2', + 'takes_bool', + 'takes_string', + 'takes_xhp_child', + 'takes_foo', + 'takes_vector_container', + 'takes_map_container', + 'takes_null', + 'takes_nonnull', + 'takes_mixed', + 'takes_vec_or_dict1', + 'takes_vec_or_dict2', + 'takes_vec_or_dict3', + ]; + + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } function test_dict_hint($x) { echo "====================================================\n"; var_dump($x); - takes_dict1($x) - |> takes_dict2($$) - |> takes_dict3($$) - |> takes_dict4($$) - |> takes_dict5($$) - |> takes_vec_or_dict1($$) - |> takes_vec_or_dict2($$) - |> takes_vec_or_dict3($$) - |> var_dump($$); + $funs = vec[ + 'takes_dict1', + 'takes_dict2', + 'takes_dict3', + 'takes_dict4', + 'takes_dict5', + 'takes_vec_or_dict1', + 'takes_vec_or_dict2', + 'takes_vec_or_dict3', + ]; + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } <<__EntryPoint>> function main(): void { set_error_handler( @@ -135,6 +154,9 @@ set_error_handler( int $errline, darray $errcontext ) ==> { + if (strpos($errstr, 'returned from')) { + throw new Exception($errstr); + } echo "ERROR: "; var_dump($errstr); return true; } diff --git a/hphp/test/quick/dict/type-hint.php.hphp_opts b/hphp/test/quick/dict/type-hint.php.hphp_opts index 8d61a23bd2a..e2dbd226bf6 100644 --- a/hphp/test/quick/dict/type-hint.php.hphp_opts +++ b/hphp/test/quick/dict/type-hint.php.hphp_opts @@ -1 +1 @@ --vHardReturnTypeHints=0 -d hhvm.php7.all=0 +-d hhvm.php7.all=0 diff --git a/hphp/test/quick/keyset/type-hint.php b/hphp/test/quick/keyset/type-hint.php index 64d2676c7f9..bcfd5cb3229 100644 --- a/hphp/test/quick/keyset/type-hint.php +++ b/hphp/test/quick/keyset/type-hint.php @@ -73,40 +73,60 @@ function takes_mixed(<<__Soft>> mixed $m): mixed { function test_all_hints($x) { echo "====================================================\n"; var_dump($x); - takes_keyset1($x) - |> takes_keyset2($$) - |> takes_keyset3($$) - |> takes_keyset4($$) - |> takes_container1($$) - |> takes_container2($$) - |> takes_keyed_container($$) - |> takes_traversable($$) - |> takes_keyed_traversable($$) - |> takes_vec($$) - |> takes_dict($$) - |> takes_bool($$) - |> takes_string($$) - |> takes_array1($$) - |> takes_array2($$) - |> takes_xhp_child($$) - |> takes_foo($$) - |> takes_vector_container($$) - |> takes_map_container($$) - |> takes_null($$) - |> takes_nonnull($$) - |> takes_mixed($$) - |> var_dump($$); + $funs = vec[ + 'takes_keyset1', + 'takes_keyset2', + 'takes_keyset3', + 'takes_keyset4', + 'takes_container1', + 'takes_container2', + 'takes_keyed_container', + 'takes_traversable', + 'takes_keyed_traversable', + 'takes_vec', + 'takes_dict', + 'takes_bool', + 'takes_string', + 'takes_array1', + 'takes_array2', + 'takes_xhp_child', + 'takes_foo', + 'takes_vector_container', + 'takes_map_container', + 'takes_null', + 'takes_nonnull', + 'takes_mixed', + ]; + + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } function test_keyset_hint($x) { echo "====================================================\n"; var_dump($x); - takes_keyset1($x) - |> takes_keyset2($$) - |> takes_keyset3($$) - |> takes_keyset4($$) - |> var_dump($$); + $funs = vec[ + 'takes_keyset1', + 'takes_keyset2', + 'takes_keyset3', + 'takes_keyset4', + ]; + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } + <<__EntryPoint>> function main(): void { set_error_handler( (int $errno, @@ -115,6 +135,9 @@ set_error_handler( int $errline, darray $errcontext ) ==> { + if (strpos($errstr, 'returned from')) { + throw new Exception($errstr); + } echo "ERROR: "; var_dump($errstr); return true; } diff --git a/hphp/test/quick/vec/type-hint.php b/hphp/test/quick/vec/type-hint.php index bbd2599ac36..c5bda2b6a30 100644 --- a/hphp/test/quick/vec/type-hint.php +++ b/hphp/test/quick/vec/type-hint.php @@ -79,44 +79,64 @@ function takes_vec_or_dict3(<<__Soft>> vec_or_dict $x): vec_or_dict { function test_all_hints($x) { echo "====================================================\n"; var_dump($x); - takes_vec1($x) - |> takes_vec2($$) - |> takes_vec3($$) - |> takes_container1($$) - |> takes_container2($$) - |> takes_keyed_container($$) - |> takes_traversable($$) - |> takes_keyed_traversable($$) - |> takes_dict($$) - |> takes_keyset($$) - |> takes_bool($$) - |> takes_string($$) - |> takes_array1($$) - |> takes_array2($$) - |> takes_xhp_child($$) - |> takes_foo($$) - |> takes_vector_container($$) - |> takes_map_container($$) - |> takes_null($$) - |> takes_nonnull($$) - |> takes_mixed($$) - |> takes_vec_or_dict1($$) - |> takes_vec_or_dict2($$) - |> takes_vec_or_dict3($$) - |> var_dump($$); + $funs = vec[ + 'takes_vec1', + 'takes_vec2', + 'takes_vec3', + 'takes_container1', + 'takes_container2', + 'takes_keyed_container', + 'takes_traversable', + 'takes_keyed_traversable', + 'takes_dict', + 'takes_keyset', + 'takes_bool', + 'takes_string', + 'takes_array1', + 'takes_array2', + 'takes_xhp_child', + 'takes_foo', + 'takes_vector_container', + 'takes_map_container', + 'takes_null', + 'takes_nonnull', + 'takes_mixed', + 'takes_vec_or_dict1', + 'takes_vec_or_dict2', + 'takes_vec_or_dict3', + ]; + + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } function test_vec_hint($x) { echo "====================================================\n"; var_dump($x); - takes_vec1($x) - |> takes_vec2($$) - |> takes_vec3($$) - |> takes_vec_or_dict1($$) - |> takes_vec_or_dict2($$) - |> takes_vec_or_dict3($$) - |> var_dump($$); + $funs = vec[ + 'takes_vec1', + 'takes_vec2', + 'takes_vec3', + 'takes_vec_or_dict1', + 'takes_vec_or_dict2', + 'takes_vec_or_dict3', + ]; + foreach($funs as $fun) { + try { + $x = $fun($x); + } catch (Exception $e) { + echo "ERROR: "; var_dump($e->getMessage()); + } + } + var_dump($x); } + <<__EntryPoint>> function main(): void { set_error_handler( (int $errno, @@ -125,6 +145,9 @@ set_error_handler( int $errline, darray $errcontext ) ==> { + if (strpos($errstr, 'returned from')) { + throw new Exception($errstr); + } echo "ERROR: "; var_dump($errstr); return true; } -- 2.11.4.GIT