lean4-htt/src/Lean/Elab
Sebastian Graf 5f4d724c2d
feat: abstract metavariables when generalizing match motives (#8099) (#11696)
This PR improves `match` generalization such that it abstracts
metavariables in types of local variables and in the result type of the
match over the match discriminants. Previously, a metavariable in the
result type would silently default to the behavior of `generalizing :=
false`, and a metavariable in the type of a free variable would lead to
an error (#8099). Example of a `match` that elaborates now but
previously wouldn't:
```lean
example (a : Nat) (ha : a = 37) :=
    (match a with | 42 => by contradiction | n => n) = 37
```
This is because the result type of the `match` is a metavariable that
was not abstracted over `a` and hence generalization failed; the result
is that `contradiction` cannot pick up the proof `ha : 42 = 37`.
The old behavior can be recovered by passing `(generalizing := false)`
to the `match`.

Furthermore, programs such as the following can now be elaborated:
```lean
example (n : Nat) : Id (Fin (n + 1)) :=
  have jp : ?m := ?rhs
  match n with
  | 0 => ?jmp1
  | n + 1 => ?jmp2
  where finally
  case m => exact Fin (n + 1) → Id (Fin (n + 1))
  case jmp1 => exact jp ⟨0, by decide⟩
  case jmp2 => exact jp ⟨n, by omega⟩
  case rhs => exact pure
```
This is useful for the `do` elaborator.

Fixes #8099.
2025-12-16 14:34:29 +00:00
..
Command feat: with_weak_namespace command (#11338) 2025-11-25 02:37:40 +00:00
Deriving feat: suggest deriving an instance when the instance might be derivable (#11346) 2025-12-01 14:28:15 +00:00
Do feat: new do elaborator, part 1: doElem_elab attribute (#11150) 2025-11-12 14:25:28 +00:00
DocString chore: fix spelling (#11531) 2025-12-06 13:54:27 +00:00
InfoTree feat: unknown identifier code action and the module system (#11164) 2025-12-12 21:19:34 +00:00
PreDefinition feat: do not have meta imply partial (#11587) 2025-12-12 11:42:42 +00:00
Quotation chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Tactic feat: abstract metavariables when generalizing match motives (#8099) (#11696) 2025-12-16 14:34:29 +00:00
Term feat: lint coercions that are deprecated or banned in core (#11511) 2025-12-12 15:09:13 +00:00
App.lean feat: identifier suggestions for non-dotted identifiers (#11619) 2025-12-11 19:47:18 +00:00
Arg.lean
Attributes.lean fix: shake: register attribute rev use independent of initialize kind (#11293) 2025-11-20 20:39:27 +00:00
AutoBound.lean feat: improve error when an identifier is unbound because autoImplicit is off (#11119) 2025-11-19 03:11:34 +00:00
AuxDef.lean
BinderPredicates.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Binders.lean chore: make auto param decls of private decls private (#11581) 2025-12-11 01:10:45 +00:00
BindersUtil.lean fix: preserve error locations when expanding match arms (#10783) 2025-10-15 13:31:42 +00:00
BuiltinCommand.lean chore: rename String.endPos -> String.rawEndPos (#10853) 2025-10-21 11:25:30 +00:00
BuiltinEvalCommand.lean refactor: make MatchEqs a leaf module (#11493) 2025-12-03 09:15:36 +00:00
BuiltinNotation.lean feat: identifier suggestions on some autobinding failures (#11621) 2025-12-11 21:40:16 +00:00
BuiltinTerm.lean chore: further shake improvements (#10947) 2025-10-26 11:27:19 +00:00
Calc.lean
CheckTactic.lean
Coinductive.lean chore: fix spelling (#11531) 2025-12-06 13:54:27 +00:00
Command.lean feat: unknown identifier code action and the module system (#11164) 2025-12-12 21:19:34 +00:00
ComputedFields.lean
Config.lean
Declaration.lean feat: shake: make Mathlib-ready (#11496) 2025-12-05 09:37:58 +00:00
DeclarationRange.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
DeclModifiers.lean feat: do not have meta imply partial (#11587) 2025-12-12 11:42:42 +00:00
DeclNameGen.lean
DeclUtil.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
DefView.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Deriving.lean feat: deriving ReflBEq and LawfulBEq (#10351) 2025-09-16 12:58:01 +00:00
Do.lean feat: new do elaborator, part 1: doElem_elab attribute (#11150) 2025-11-12 14:25:28 +00:00
DocString.lean chore: fix typo "Unkown" -> "Unknown" in role error message (#11682) 2025-12-15 14:29:11 +00:00
ElabRules.lean feat: new do elaborator, part 1: doElem_elab attribute (#11150) 2025-11-12 14:25:28 +00:00
ErrorExplanation.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
ErrorUtils.lean feat: hint when an autobound variable's type fails to be a function (#11518) 2025-12-05 03:07:16 +00:00
Eval.lean
Exception.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Extra.lean
Frontend.lean feat: reduce server memory consumption (#11162) 2025-12-01 10:53:23 +00:00
GenInjective.lean
GuardMsgs.lean refactor: use String.split instead of String.splitOn or String.splitToList (#11250) 2025-11-19 09:35:19 +00:00
Import.lean fix: symbol clashes between packages (#11082) 2025-11-19 02:24:44 +00:00
Inductive.lean chore: make declMetaExt persistent for shake (#11201) 2025-11-16 20:11:56 +00:00
InfoTree.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
InfoTrees.lean
InheritDoc.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
LetRec.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Level.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Macro.lean
MacroArgUtil.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
MacroRules.lean chore: error messages consistency (#10143) 2025-08-26 17:55:43 +00:00
Match.lean feat: abstract metavariables when generalizing match motives (#8099) (#11696) 2025-12-16 14:34:29 +00:00
MatchAltView.lean
MatchExpr.lean
Mixfix.lean feat: enable notationItem in "mixfix" notation commands (#10378) 2025-09-14 18:54:36 +00:00
MutualDef.lean feat: unknown identifier code action and the module system (#11164) 2025-12-12 21:19:34 +00:00
MutualInductive.lean chore: fix spelling (#11531) 2025-12-06 13:54:27 +00:00
Notation.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Open.lean feat: backward.privateInPublic option (#10807) 2025-10-16 20:51:45 +00:00
Parallel.lean refactor: move Iter and others from Std.Iterators to Std (#11446) 2025-12-15 08:24:12 +00:00
ParseImportsFast.lean refactor: move operations on String.Pos.Raw to the String.Pos.Raw namespace (#10735) 2025-10-18 12:12:55 +00:00
PatternVar.lean feat: suggestions for ambiguous dotted identifiers (#11555) 2025-12-09 17:27:22 +00:00
PreDefinition.lean feat: generate equational theorems uniformly (#10734) 2025-10-10 21:35:09 +00:00
Print.lean chore: make declMetaExt persistent for shake (#11201) 2025-11-16 20:11:56 +00:00
Quotation.lean refactor: use String.Slice in String.take and variants (#11180) 2025-11-18 16:13:48 +00:00
RecAppSyntax.lean
RecommendedSpelling.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
SetOption.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
StructInst.lean chore: fix spelling (#11531) 2025-12-06 13:54:27 +00:00
StructInstHint.lean refactor: deprecate String.posOf and variants in favor of unified String.find (#11276) 2025-11-23 18:39:53 +00:00
Structure.lean chore: make declMetaExt persistent for shake (#11201) 2025-11-16 20:11:56 +00:00
Syntax.lean refactor: use String.Slice in String.take and variants (#11180) 2025-11-18 16:13:48 +00:00
SyntheticMVars.lean fix: ensure by uses expected instead of given type for modsys aux decl (#11673) 2025-12-14 17:44:38 +00:00
Tactic.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Task.lean feat: parallelism utilities for MetaM/TacticM (#11333) 2025-11-24 23:42:30 +00:00
Term.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Time.lean
Util.lean fix: when constructing instance names, avoid private names (#11385) 2025-11-26 18:16:44 +00:00
WhereFinally.lean