Skip to content

feat: mutually dependent structure default values, and avoiding self-dependence#12841

Merged
kmill merged 3 commits intomasterfrom
kmill_structure_mutual_defaults
Mar 9, 2026
Merged

feat: mutually dependent structure default values, and avoiding self-dependence#12841
kmill merged 3 commits intomasterfrom
kmill_structure_mutual_defaults

Conversation

@kmill
Copy link
Copy Markdown
Collaborator

@kmill kmill commented Mar 8, 2026

This PR changes the elaboration of the structure/class commands so that default values have later fields in context as well. This allows field defaults to depend on fields that come both before and after them. While this was already the case for inherited fields to some degree, it now applies uniformly to all fields. Additionally, when elaborating the default value for a field, all fields that depend on it are cleared from the context to avoid situations where the default value depends on itself.

This addresses an issue reported by Aaron Liu on Zulip.

…nce checking

This PR changes the way default field values are elaborated in the `structure`/`class` commands so that they have all the fields in context. This allows the field defaults to be dependent on one another, which is already allowed for default values for inherited fields. Additionally, there is now an error that's logged if a field default depends on itself. Such fields will never be applicable.

This fixes a bug reported by Aaron Liu [on Zulip](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/default.20structure.20values.20can.20depend.20on.20themselves/near/578014370)
@kmill kmill added the changelog-language Language features and metaprograms label Mar 8, 2026
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Mar 8, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-05 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-03-08 20:45:24)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 8, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Mar 8, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 8, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Mar 8, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 8, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 8, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Mar 9, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

@kmill kmill changed the title feat: mutually dependent structure default values, and self-dependence checking feat: mutually dependent structure default values, and avoiding self-dependence Mar 9, 2026
@kmill kmill added this pull request to the merge queue Mar 9, 2026
Merged via the queue into master with commit 27b583d Mar 9, 2026
32 checks passed
sgraf812 pushed a commit that referenced this pull request Mar 9, 2026
…f-dependence (#12841)

This PR changes the elaboration of the `structure`/`class` commands so
that default values have later fields in context as well. This allows
field defaults to depend on fields that come both before and after them.
While this was already the case for inherited fields to some degree, it
now applies uniformly to all fields. Additionally, when elaborating the
default value for a field, all fields that depend on it are cleared from
the context to avoid situations where the default value depends on
itself.

This addresses an issue reported by Aaron Liu [on
Zulip](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/default.20structure.20values.20can.20depend.20on.20themselves/near/578014370).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants