Skip to content

Commit

Permalink
Merge PR #18369: Ltac2.Char.of_int: use throw instead of raw except…
Browse files Browse the repository at this point in the history
…ion for invalid argument

Reviewed-by: ppedrot
Co-authored-by: ppedrot <ppedrot@users.noreply.github.com>
  • Loading branch information
coqbot-app[bot] and ppedrot committed Dec 11, 2023
2 parents e9f7bb8 + 3ab1562 commit c3306d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plugins/ltac2/tac2core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ let () = define "int_lnot" (int @-> ret int) lnot

(** Char *)

let () = define "char_of_int" (int @-> ret char) Char.chr
let () = define "char_of_int" (int @-> tac char) @@ fun i ->
try return (Char.chr i)
with Invalid_argument _ as e ->
let e, info = Exninfo.capture e in
throw ~info e

let () = define "char_to_int" (char @-> ret int) Char.code

(** String *)
Expand Down
2 changes: 2 additions & 0 deletions user-contrib/Ltac2/Char.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Require Import Ltac2.Init.
Require Ltac2.Int.

Ltac2 @external of_int : int -> char := "coq-core.plugins.ltac2" "char_of_int".
(** Throws if the integer is not a valid char (in range [0-255]). *)

Ltac2 @external to_int : char -> int := "coq-core.plugins.ltac2" "char_to_int".

Ltac2 equal (x : char) (y : char) : bool := Int.equal (to_int x) (to_int y).
Expand Down

0 comments on commit c3306d6

Please sign in to comment.