Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty-printer: consistently print nested tuples with (,) syntax #3100

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ocaml/fstar-lib/generated/FStar_Parser_ToDocument.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/parser/FStar.Parser.ToDocument.fst
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,10 @@ and p_appTerm e = match e.tm with
group (soft_surround_map_or_flow 2 0 head_doc (head_doc ^^ space) break1 empty p_argTerm args)
)

(* (explicit) dependent tuples are handled below *)
(* (explicit) tuples and dependent tuples are handled below *)
| Construct (lid, args) when is_general_construction e
&& not (is_dtuple_constructor lid && all1_explicit args) ->
&& not (is_dtuple_constructor lid && all1_explicit args)
&& not (is_tuple_constructor lid && all1_explicit args) ->
begin match args with
| [] -> p_quident lid
| [arg] -> group (p_quident lid ^/^ p_argTerm arg)
Expand Down Expand Up @@ -2074,6 +2075,8 @@ and p_atomicTermNotQUident e = match e.tm with
surround 2 1 (lparen ^^ bar)
(separate_map (comma ^^ break1) (fun (e, _) -> p_tmEq e) args)
(bar ^^ rparen)
| Construct (lid, args) when is_tuple_constructor lid && all1_explicit args ->
parens (p_tmTuple e)
| Project (e, lid) ->
group (prefix 2 0 (p_atomicTermNotQUident e) (dot ^^ p_qlident lid))
| _ ->
Expand Down
11 changes: 11 additions & 0 deletions tests/error-messages/Bug3099.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(* Test case: nested tuples print strangely in tactic dumps.
They look OK with --print_in_place though.
(This isn't strictly an error message test, but it is testing debug
messages, which are important too.)
*)
module Bug3099

module Tac = FStar.Tactics

let check_print_tuples () =
assert ((1, (2, (3, 4))) = (1, (2, (3, 4)))) by (Tac.dump "X")
7 changes: 7 additions & 0 deletions tests/error-messages/Bug3099.fst.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
proof-state: State dump @ depth 0 (X):
Location: Bug3099.fst(11,50-11,64)
Goal 1/1:
(_: Prims.unit), (return_val: Prims.eqtype), (_: return_val == Prims.int * Prims.int * Prims.int * Prims.int), (any_result: Prims.bool), (_: true == any_result), (any_result'0: Prims.logical), (_: Prims.l_True == any_result'0) |- _ : Prims.squash ((1, (2, (3, 4))) = (1, (2, (3, 4))))

Verified module: Bug3099
All verification conditions discharged successfully