Permalink
Browse files

Fix case insensitivity when checking for duplicated names

Summary: Constants are case sensitive, but everything else is case insensitive.

Reviewed By: vassilmladenov

Differential Revision: D7436721

fbshipit-source-id: 2d1833d65226bc1b5b041516a1cbf11b3003eaef
  • Loading branch information...
jamesjwu authored and hhvm-bot committed Apr 5, 2018
1 parent 7a7b8c4 commit ba940ecdc4a2701dade8728b535062a4bc0962ba
Showing with 13 additions and 7 deletions.
  1. +13 −6 hphp/hack/src/parser/full_fidelity_parser_errors.ml
  2. +0 −1 hphp/test/hhcodegen_failing_tests_zend
@@ -1949,6 +1949,7 @@ let expression_errors env node parents errors =
make_error_from_node node SyntaxError.elvis_operator_space :: errors
| _ -> errors (* Other kinds of expressions currently produce no expr errors. *)
let require_errors env node parents trait_use_clauses errors =
match syntax node with
| RequireClause p ->
@@ -2209,12 +2210,17 @@ let use_class_or_namespace_clause_errors
| Some p -> combine_names p name_text in
let short_name = get_short_name_from_qualified_name name_text (text alias) in
let do_check ~error_on_global_redefinition names errors
let do_check ?(case_sensitive = false) ~error_on_global_redefinition names errors
get_map update_map report_error =
(* We store the original names in the SMap of names for error messaging purposes
but we check for case sensitivity specifically. *)
let find_name name =
if case_sensitive
then short_name = name
else (String.lowercase_ascii short_name) = String.lowercase_ascii name in
let map = get_map names in
match SMap.get short_name map with
| Some { f_location = location; f_kind; _ } ->
match SMap.find_first_opt find_name map with
| Some (_, { f_location = location; f_kind; _ }) ->
if (f_kind <> Name_def
|| (error_on_global_redefinition && is_global_namespace))
then
@@ -2230,7 +2236,8 @@ let use_class_or_namespace_clause_errors
~kind:Name_use
(make_location_of_node name)
global_namespace_name qualified_name in
update_map names (SMap.add short_name new_use map), errors in
update_map names (SMap.add short_name new_use map), errors
in
begin match syntax kind with
| Token token ->
@@ -2255,7 +2262,7 @@ let use_class_or_namespace_clause_errors
SyntaxError.function_name_is_already_in_use
| Const ->
do_check ~error_on_global_redefinition:true names errors
do_check ~case_sensitive:true ~error_on_global_redefinition:true names errors
(fun n -> n.t_constants)
(fun n v -> { n with t_constants = v })
SyntaxError.const_name_is_already_in_use
@@ -1,6 +1,5 @@
zend/good/Zend/tests/errmsg_039.php
zend/good/Zend/tests/objects_026.php
zend/good/Zend/tests/try_catch_finally_007.php
zend/good/Zend/tests/use_function/case_insensivity.php
zend/good/Zend/tests/use_function/no_global_fallback2.php
zend/good/ext/standard/tests/serialize/006.php

0 comments on commit ba940ec

Please sign in to comment.