From df9cc6121434b38befe7fc077fe12546eab4148a Mon Sep 17 00:00:00 2001 From: Burnleydev1 Date: Tue, 22 Aug 2023 12:04:41 +0100 Subject: [PATCH] applying requested changes. Signed-off-by: Burnleydev1 --- src/context_free.ml | 18 ++++++++---------- test/driver/exception_handling/run.t | 4 ++-- .../exception_handling/special_functions.ml | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/context_free.ml b/src/context_free.ml index efced3382..40a661231 100644 --- a/src/context_free.ml +++ b/src/context_free.ml @@ -518,30 +518,28 @@ class map_top_down ?(expect_mismatch_handler = Expect_mismatch_handler.nop) | None -> self#pexp_apply_without_traversing_function base_ctxt e func args | Some pattern -> ( - let pat_expr = - try (pattern e, []) + let generated_code = + try return (pattern e) with exn when embed_errors -> (None, [ exn_to_error exn ]) in - pat_expr >>= fun expr -> + generated_code >>= fun expr -> match expr with | None -> self#pexp_apply_without_traversing_function base_ctxt e func args - | Some e -> self#expression base_ctxt e - (* with exn when embed_errors -> (e, [ exn_to_error exn ]) *))) + | Some e -> self#expression base_ctxt e)) | Pexp_ident id -> ( match Hashtbl.find_opt special_functions id.txt with | None -> super#expression base_ctxt e | Some pattern -> ( - let pat_exp = - try (pattern e, []) + let generated_code = + try return (pattern e) with exn when embed_errors -> (None, [ exn_to_error exn ]) in - pat_exp >>= fun expr -> + generated_code >>= fun expr -> match expr with | None -> super#expression base_ctxt e - | Some e -> self#expression base_ctxt e - (* with exn when embed_errors -> (e, [ exn_to_error exn ]) *))) + | Some e -> self#expression base_ctxt e)) | Pexp_constant (Pconst_integer (s, Some c)) -> ( try expand_constant Integer c s with exn when embed_errors -> (e, [ exn_to_error exn ])) diff --git a/test/driver/exception_handling/run.t b/test/driver/exception_handling/run.t index 795954f63..9f3430e74 100644 --- a/test/driver/exception_handling/run.t +++ b/test/driver/exception_handling/run.t @@ -193,12 +193,12 @@ when the -embed-errors flag is not passed When embed-errors is not passed $ ./special_functions.exe impl.ml File "impl.ml", lines 1-2, characters 0-7: - Error: error special function + Error: error special function [1] When embed-errors is not passed $ ./special_functions.exe -embed-errors impl.ml - [%%ocaml.error "error special function "] + [%%ocaml.error "error special function"] [%%ocaml.error "second error special function"] ;;n_args n_args2 diff --git a/test/driver/exception_handling/special_functions.ml b/test/driver/exception_handling/special_functions.ml index 09b24bb58..3d3bbc365 100644 --- a/test/driver/exception_handling/special_functions.ml +++ b/test/driver/exception_handling/special_functions.ml @@ -1,6 +1,6 @@ open Ppxlib -let expand e = Location.raise_errorf ~loc:e.pexp_loc "error special function " +let expand e = Location.raise_errorf ~loc:e.pexp_loc "error special function" let expand2 e = Location.raise_errorf ~loc:e.pexp_loc "second error special function"