From 9ef594545d6ac68920c1875c8186cbfd5d6b3029 Mon Sep 17 00:00:00 2001 From: Sasha Manzyuk Date: Tue, 2 Jul 2019 07:19:07 -0700 Subject: [PATCH] Improve the error message of "primary error position not in current file" errors Summary: Make it clear in the error message that this is a bug in the type checker that should be reported to the Hack team and provide instructions for doing that. Reviewed By: andrewjkennedy Differential Revision: D16074272 fbshipit-source-id: bc8e4737a0608573ad344d0324bfc1d6521e77b3 --- hphp/hack/src/errors/dune | 5 ++++- hphp/hack/src/errors/errors.ml | 7 ++++--- hphp/hack/src/stubs/badpos_sentinel.ml | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 hphp/hack/src/stubs/badpos_sentinel.ml diff --git a/hphp/hack/src/errors/dune b/hphp/hack/src/errors/dune index a15e84d6ec0..423bf88bcf4 100644 --- a/hphp/hack/src/errors/dune +++ b/hphp/hack/src/errors/dune @@ -8,4 +8,7 @@ server_load_flag (select coroutine_errors.ml from (facebook -> facebook/coroutine_errors.ml) - (-> ../stubs/coroutine_errors.ml)))) + (-> ../stubs/coroutine_errors.ml)) + (select badpos_sentinel.ml from + (facebook -> facebook/badpos_sentinel.ml) + (-> ../stubs/badpos_sentinel.ml)))) diff --git a/hphp/hack/src/errors/errors.ml b/hphp/hack/src/errors/errors.ml index 0dbe3d4a059..b9a4e961dc6 100644 --- a/hphp/hack/src/errors/errors.ml +++ b/hphp/hack/src/errors/errors.ml @@ -110,7 +110,6 @@ let (error_map : error files_t ref) = ref Relative_path.Map.empty let accumulate_errors = ref false (* Some filename when declaring *) let in_lazy_decl = ref None -let badpos_sentinel = "PRIMARY ERROR POSITION IS NOT IN CURRENT FILE: please fix" let try_with_result f1 f2 = let error_map_copy = !error_map in @@ -132,7 +131,9 @@ let try_with_result f1 f2 = | Some (code,l) -> (* Remove bad position sentinel if present: we might be about to add a new primary * error position*) - let l = match l with (_, msg) :: l when msg = badpos_sentinel -> l | _ -> l in + let l = match l with + | (_, msg) :: l when msg = Badpos_sentinel.message -> l + | _ -> l in f2 result (code,l) let do_ f = @@ -587,7 +588,7 @@ let check_pos_msg pos_msg_l = let pos = fst (List.hd_exn pos_msg_l) in let current_file = fst !current_context in if current_file <> Relative_path.default && Pos.filename pos <> current_file - then (pos, badpos_sentinel) :: pos_msg_l + then (Pos.make_from current_file, Badpos_sentinel.message) :: pos_msg_l else pos_msg_l let rec add_applied_fixme code pos = diff --git a/hphp/hack/src/stubs/badpos_sentinel.ml b/hphp/hack/src/stubs/badpos_sentinel.ml new file mode 100644 index 00000000000..129adf863a7 --- /dev/null +++ b/hphp/hack/src/stubs/badpos_sentinel.ml @@ -0,0 +1,12 @@ +(** + * Copyright (c) 2018, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the "hack" directory of this source tree. + * + *) + +let message = + "Type checking of this file produced an error with the primary position " ^ + "in a different file. Please file a bug." -- 2.11.4.GIT