fix: elaborate section variables with the visibility of the enclosing scope This PR fixes anonymous `public` instances being silently dropped, and `public axiom`, `public structure`, and `public inductive` failing with a misplaced error, when an unused section variable mentions a private declaration in a `module`. `runTermElabM` elaborated the section variables with whatever visibility was current. `elabMutualDef` runs `mkDefView` under `withExporting` with the declaration's own visibility, and for an anonymous instance `mkDefView` calls `mkInstanceName`, which uses `runTermElabM`. So `variable [C]` with a private class `C` was elaborated in exporting mode, where `C` is not accessible, and the instance-implicit binder check threw. `mkInstanceName` discards the messages logged during name generation, and `logAt` suppresses the escaping exception because its message contains a synthetic `sorry`, so the failure was silent. `runTermElabM` now elaborates the section variables with the visibility of the enclosing scope, as `elabDeclaration` already does at the top level, and restores the caller's visibility only around `elabFn`. Closes #15302 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This is the repository for Lean 4.
See Install Lean.
Please read our Contribution Guidelines first.
See Building Lean.