From dd1f7cd4f46a61c49c1705799d8a1cea2a0128e0 Mon Sep 17 00:00:00 2001 From: Andrew Kennedy Date: Tue, 2 Jan 2018 10:19:47 -0800 Subject: [PATCH] Reuse of classes in use statement Summary: Fixed a bug in the `combine_names` function that revealed some issues with `use` redefinition errors. Differential Revision: D6649813 fbshipit-source-id: c43c5a9a783a553e601a9f4c09c701a02576fda3 --- hphp/hack/src/parser/full_fidelity_parser_errors.ml | 14 +++++++------- hphp/test/hackc_failing_tests_slow | 1 - hphp/test/hackc_repo_failing_tests_slow | 3 +-- hphp/test/hhcodegen_failing_tests_slow | 2 -- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/hphp/hack/src/parser/full_fidelity_parser_errors.ml b/hphp/hack/src/parser/full_fidelity_parser_errors.ml index f537110ae59..89b228ff1db 100644 --- a/hphp/hack/src/parser/full_fidelity_parser_errors.ml +++ b/hphp/hack/src/parser/full_fidelity_parser_errors.ml @@ -70,7 +70,7 @@ let combine_names n1 n2 = let len = String.length n1 in let has_trailing_slash = String.get n1 (len - 1) = '\\' in match has_leading_slash, has_trailing_slash with - | true, true -> n1 ^ (String.sub n2 1 (len - 1)) + | true, true -> n1 ^ (String.sub n2 1 (String.length n2 - 1)) | false, false -> n1 ^ "\\" ^ n2 | _ -> n1 ^ n2 @@ -1693,7 +1693,8 @@ let require_errors node parents hhvm_compat_mode trait_use_clauses errors = let check_type_name name namespace_name name_text location names errors = begin match SMap.get name_text names.t_classes with - | Some { f_location = location; f_is_def = false; _ } -> + | Some { f_location = location; f_is_def = false; f_name } + when combine_names namespace_name name_text <> f_name -> let error = make_name_already_used_error name name_text name_text location SyntaxError.type_name_is_already_in_use in @@ -1878,9 +1879,8 @@ let use_class_or_namespace_clause_errors let map = get_map names in match SMap.get short_name map with - | Some { f_location = location; f_is_def = is_definition; f_name } -> - if qualified_name <> f_name && - (not is_definition + | Some { f_location = location; f_is_def = is_definition; _ } -> + if (not is_definition || (error_on_global_redefinition && is_global_namespace)) then let error = @@ -1940,8 +1940,8 @@ let use_class_or_namespace_clause_errors let names, errors = let location = make_location_of_node name in match SMap.get short_name names.t_classes with - | Some { f_location = loc; f_name; _ } -> - if qualified_name = f_name then names, errors + | Some { f_location = loc; f_name; f_is_def; _ } -> + if qualified_name = f_name && f_is_def then names, errors else let error = make_name_already_used_error name name_text short_name loc diff --git a/hphp/test/hackc_failing_tests_slow b/hphp/test/hackc_failing_tests_slow index 9f9cfe8a94b..4ecb30ab528 100644 --- a/hphp/test/hackc_failing_tests_slow +++ b/hphp/test/hackc_failing_tests_slow @@ -24,7 +24,6 @@ slow/inout/method-interop-static.php slow/inout/side-effects.php slow/inout/trait-magic.php slow/parser/hh-namespace-conflict-2.php -slow/parser/hh-namespace-conflict-3.php slow/parser/hh-namespace-conflict-6.php slow/return_statement/finally-typecheck.php slow/using/bad-async.php diff --git a/hphp/test/hackc_repo_failing_tests_slow b/hphp/test/hackc_repo_failing_tests_slow index d0b64cc47bb..ea03f053a11 100644 --- a/hphp/test/hackc_repo_failing_tests_slow +++ b/hphp/test/hackc_repo_failing_tests_slow @@ -16,7 +16,6 @@ slow/hh_namespace_migration/hh_vector5.php slow/inout/bad-call-15.php slow/inout/side-effects.php slow/parser/hh-namespace-conflict-2.php -slow/parser/hh-namespace-conflict-3.php slow/parser/hh-namespace-conflict-6.php slow/return_statement/finally-typecheck.php slow/traits/require_constraint_basic_error.php @@ -25,4 +24,4 @@ slow/using/bad-async.php slow/using/bad-function3.php slow/using/bad-function4.php slow/using/bad-goto1.php -slow/using/bad-goto2.php \ No newline at end of file +slow/using/bad-goto2.php diff --git a/hphp/test/hhcodegen_failing_tests_slow b/hphp/test/hhcodegen_failing_tests_slow index d82772b5cf0..96eadcbe11e 100644 --- a/hphp/test/hhcodegen_failing_tests_slow +++ b/hphp/test/hhcodegen_failing_tests_slow @@ -3,9 +3,7 @@ slow/hh_namespace_migration/hh_vector5.php slow/inout/bad-call-15.php slow/inout/side-effects.php slow/parser/hh-namespace-conflict-2.php -slow/parser/hh-namespace-conflict-3.php slow/parser/hh-namespace-conflict-6.php -slow/parser/php-namespace-conflict-3.php slow/php7_backported/ns_093.php slow/reflection/param_tostring_zendcompat.php slow/using/goto.php \ No newline at end of file -- 2.11.4.GIT