8000 fix: strip optional parameters when elaborating the termination hints by wkrozowski · Pull Request #7335 · leanprover/lean4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: strip optional parameters when elaborating the termination hints #7335

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

Merged
merged 4 commits into from
Mar 5, 2025
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
3 changes: 1 addition & 2 deletions src/Lean/Elab/PreDefinition/TerminationMeasure.lean
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Elaborates a `TerminationBy` to an `TerminationMeasure`.
def TerminationMeasure.elab (funName : Name) (type : Expr) (arity extraParams : Nat)
(hint : TerminationBy) : TermElabM TerminationMeasure := withDeclName funName do
assert! extraParams ≤ arity

if h : hint.vars.size > extraParams then
let mut msg := m!"{parameters hint.vars.size} bound in `termination_by`, but the body of " ++
m!"{funName} only binds {parameters extraParams}."
Expand All @@ -64,7 +63,7 @@ def TerminationMeasure.elab (funName : Name) (type : Expr) (arity extraParams :

-- Bring parameters before the colon into scope
let r ← withoutErrToSorry <|
forallBoundedTelescope type (arity - extraParams) fun ys type' => do
forallBoundedTelescope (cleanupAnnotations := true) type (arity - extraParams) fun ys type' => do
-- Bring the variables bound by `termination_by` into scope.
elabFunBinders hint.vars (some type') fun xs type' => do
-- Elaborate the body in this local environment
Expand Down
9 changes: 9 additions & 0 deletions tests/lean/run/issue6531.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- This used to cause
-- error: The termination argument's type must not depend on the function's varying parameters

def foo (as : Array Nat) (i := 0) (j := as.size - 1) : Array Nat :=
if j ≤ i then as
else
let newas := as.set! 0 0
foo newas (i+1) (j-1)
termination_by j - i
Loading
0