coqc -beautify outputs syntactically and semantically invalid code
samuelgruetter opened this issue · comments
$ cat toBeautify.v
Inductive Foo := Foo1 | Foo2 | Foo3.
Definition isFoo12(f: Foo): bool :=
match f with
| Foo1 => true
| Foo2 => true
| _ => false
end.
$ coqc -beautify ./toBeautify.v
$ cat toBeautify.v.beautified
Inductive Foo :=
| Foo1 : _
| Foo2 : _
| Foo3 : _.Definition isFoo12 (f : Foo) :
bool := match f with
| _ => false
| _ => true
end.
$ mv toBeautify.v.beautified toBeautify2.v
$ coqc toBeautify2.v
File "./toBeautify2.v", line 4, characters 12-23:
Error: Syntax error: '.' expected after [vernac:gallina] (in [vernac_aux]).
(edit ./toBeautify2.v
to fix the syntax error)
$ coqc toBeautify2.v
File "./toBeautify2.v", line 9, characters 12-21:
Error: Pattern "_" is redundant in this clause.
$ coqc --version
The Coq Proof Assistant, version 8.11+alpha (November 2019)
compiled on Nov 4 2019 14:19:52 with OCaml 4.09.0
When beautifying we pass terms through intern/extern (not sure why).
When externing the match, we select Foo1 | Foo2 => true
as the default clause (because 2 cases becoming an underscore is better than 1), but this causes ambiguity with the already present default clause.
Usually we extern glob_constr which come from constr, such that they have no default clause, so this isn't an issue.
I guess we could add a check in select_default_clause that there isn't already one. Not sure if this would leave related issues.