From af6cd08ff464ebbf7f5eee6507408559bb97c72d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 13 Apr 2017 15:23:22 +0200 Subject: [PATCH] fix too restrictive type in `CCResult` --- src/core/CCResult.ml | 8 ++++++++ src/core/CCResult.mli | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index c44ab774..0d00755c 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -24,6 +24,10 @@ let fail_printf format = (fun buf -> fail (Buffer.contents buf)) buf format +(*$T + (Error "ohno 42") = (fail_printf "ohno %d" 42) +*) + let fail_fprintf format = let buf = Buffer.create 64 in let out = Format.formatter_of_buffer buf in @@ -31,6 +35,10 @@ let fail_fprintf format = (fun out -> Format.pp_print_flush out (); fail (Buffer.contents buf)) out format +(*$T + (Error "ohno 42") = (fail_fprintf "ohno %d" 42) +*) + let add_ctx msg x = match x with | Error e -> Error (e ^ "\ncontext:" ^ msg) | Ok x -> Ok x diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 0f3f00f6..9c6a9b49 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -34,11 +34,11 @@ val of_exn_trace : exn -> ('a, string) t Remember to call [Printexc.record_backtrace true] and compile with the debug flag for this to work. *) -val fail_printf : ('a, Buffer.t, unit, ('a, string) t) format4 -> 'a +val fail_printf : ('a, Buffer.t, unit, ('b, string) t) format4 -> 'a (** [fail_printf format] uses [format] to obtain an error message and then returns [Error msg] *) -val fail_fprintf : ('a, Format.formatter, unit, ('a, string) t) format4 -> 'a +val fail_fprintf : ('a, Format.formatter, unit, ('b, string) t) format4 -> 'a (** [fail_printf format] uses [format] to obtain an error message and then returns [Error msg] *)