Lean 4 fork for HoTT-compatible kernel extensions (Path types, transport, HITs). Maintained against upstream leanprover/lean4.
This PR adds missing type checking for pattern variables during pattern matching/unification to prevent incorrect matches. Previously, the pattern matcher could incorrectly match expressions even when pattern variable types were incompatible with the matched subterm types. For example, a pattern like `x` where `x : BitVec 0` could match any term, ignoring the specific type constraint on `x`. This PR introduces a two-phase type checking approach: 1. **Static analysis** (`mkCheckTypeMask`): Identifies which pattern variables require type checking based on their syntactic position. Variables that appear only as arguments to function applications skip checking (the application structure already constrains their types), while variables in function position, binder contexts, or standalone positions must be checked. 2. **Runtime validation**: During matching, when a pattern variable is assigned, its type is checked against the matched subterm's type if flagged by the mask. Checking uses `withReducible` to balance soundness and performance. The PR also adds helper functions for debugging (`Sym.mkMethods`, `Sym.simpWith`, `Sym.simpGoal`) and fixes a minor issue where `Theorem.rewrite` could return `.step` with identical expressions instead of `.rfl`.Body: |
||
|---|---|---|
| .claude | ||
| .github | ||
| doc | ||
| images | ||
| releases_drafts | ||
| script | ||
| src | ||
| stage0 | ||
| tests | ||
| .gitattributes | ||
| .gitignore | ||
| .gitpod.Dockerfile | ||
| .gitpod.yml | ||
| .ignore | ||
| CMakeLists.txt | ||
| CMakePresets.json | ||
| CODEOWNERS | ||
| CONTRIBUTING.md | ||
| flake.lock | ||
| flake.nix | ||
| lean-toolchain | ||
| lean.code-workspace | ||
| LICENSE | ||
| LICENSES | ||
| README.md | ||
| RELEASES.md | ||
This is the repository for Lean 4.
About
- Quickstart
- Homepage
- Theorem Proving Tutorial
- Functional Programming in Lean
- Documentation Overview
- Language Reference
- Release notes starting at v4.0.0-m3
- Examples
- External Contribution Guidelines
Installation
See Install Lean.
Contributing
Please read our Contribution Guidelines first.
Building from Source
See Building Lean.