Skip to content

Improve the arity error message for destructuring let - #22314

Open
MavenRain wants to merge 1 commit into
rocq-prover:masterfrom
MavenRain:7833-lettuple-arity-error
Open

Improve the arity error message for destructuring let#22314
MavenRain wants to merge 1 commit into
rocq-prover:masterfrom
MavenRain:7833-lettuple-arity-error

Conversation

@MavenRain

Copy link
Copy Markdown
Contributor

Fixes / closes #7833

Explanation

The arity error for a destructuring let used to be a bare user_err in the
pretyper:

Destructing let on this type expects 2 variables.

It now names the destructured term and its type, and reports the number of
variables actually given:

Destructing let on term "p" of type "point2d"
expects 2 variables, but 3 were given.

As requested in the review of the earlier attempt #7943, no Printer call is
made inside pretyping: the error is a new Pretype_errors.pretype_error
constructor (LetTupleArity, carrying the judgment of the destructured term
plus the expected and given variable counts) raised through a new
error_lettuple_arity helper and rendered in Himsg, mirroring the
neighboring CaseNotInductive / NumberBranches plumbing.

API note: Pretype_errors.pretype_error gains the LetTupleArity
constructor, so external plugin code matching exhaustively on
pretype_error needs a new arm. In-tree code needed no change besides
Himsg.

The new output test covers both plural renderings in each position
("expects 1 variable" / "expects 2 variables", "1 was given" / "3 were
given").

  • Added / updated test-suite (test-suite/output/bug_7833.v).
  • Added changelog.

Drafted with AI assistance; the change and its verification (full build,
output test-suite, mutation check on the new test) were reviewed and run
locally by me.

@MavenRain
MavenRain requested review from a team as code owners July 27, 2026 09:15
@coqbot-app coqbot-app Bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Jul 27, 2026
"Destructing let on this type expects 2 variables." now names the
destructured term and its type, and reports how many variables were
given:

  Destructing let on term "p" of type "point2d"
  expects 2 variables, but 3 were given.

Following the review guidance on the earlier attempt rocq-prover#7943, the error
is plumbed as a proper Pretype_errors constructor (LetTupleArity)
rendered in Himsg, instead of a raw user_err inside the pretyper.

Fixes rocq-prover#7833

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain
MavenRain force-pushed the 7833-lettuple-arity-error branch from f01ee09 to db3d1ea Compare July 27, 2026 09:34
@SkySkimmer

Copy link
Copy Markdown
Contributor

I'm not sure we want to print the full term and type. They can be arbitrarily large. Also we have the error location pointing at the term so printing it seems redundant.
Maybe just print the name of the inductive? eg

Destructing let on term of type "prod"
expects 2 variables, but 3 were given.

(where the full type would be prod nat nat printed nat * nat)

(but I have a strong bias towards brevity, so maybe the average user would benefit from the full term & type? IDK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Try to provide better error messages on destructuring with let

2 participants