fix(language): a cases block with one case may compare expressions in its when: - #795
Merged
Merged
Conversation
… its when: The otherwise is the complement of the cases, so one case overlaps nothing. Two or more cases that compare expressions are still refused as a pair.
FabianHofmann
requested review from
FBumann and
brynpickering
as code owners
September 30, 2026 11:09
Documentation build overview
3 files changed± changelog/index.html± reference/language/expressions/index.html± reference/language/named/index.html |
FBumann
approved these changes
Sep 30, 2026
Contributor
|
@FabianHofmann Feel free to merge |
FBumann
pushed a commit
that referenced
this pull request
Oct 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PBmqeqBrqpQC6MVoSrguHK
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
The following content was generated by AI.
A
cases:block with one case may now compare expressions in itswhen:. Theotherwise:is the complement of the cases, so one case overlaps nothing. Two or more such cases are still refused.Closes #794
Method, gate output, alternatives
Why the refusal can go
otherwiseis built as the complement of the cases (remainderinsrc/mathspec/resolution.py:263-273). A single case cannot overlap it, so the message "theotherwiseis its negation" gave no reason to refuse.src/mathspec/_where_resolver.py:364-373). Awhen:comparison only compares parameters.where:has accepted comparisons of expressions since feat(language): a where may compare arithmetic over parameters #566.shift(<cmp>, along=period, offset=0), which loaded.The change
src/mathspec/exclusivity.py:_undecidedand the per-case refusal inoverlappingare deleted. The pair check did not need them:_observealready raisesUndecidablewith_expression_rewritefor anExpressionComparison, so a pair that compares expressions is refused as before, now once per pair instead of once per case. The message "Theotherwiseis its negation" is gone with it.docs/reference/language/named.mdanddocs/reference/language/expressions.md: the rule now applies to a block of two or more cases.Failing test first
tests/test_validation.py::TestAWhereSideIsReadInResolution::test_a_lone_case_comparing_expressions_loadsreplacestest_a_lone_case_comparing_expressions_is_refused_too. It loads a block with one casec > 2 * k, reads the YAML back to the same program, and prints it in latex, markdown and typst. On the unfixed tree:After the fix: 3 passed.
Where the coverage of the old tests moved
The fix with the old tests gave 3 failed, 2596 passed:
test_validation.py::test_a_lone_case_comparing_expressions_is_refused_too: replaced by the test above, which asserts the opposite.test_exclusivity.py::test_a_literal_written_first_is_named_as_the_order_it_isandtest_a_comparison_of_real_expressions_keeps_the_general_refusal: they unpacked two refusals, one per case. They now unpack one refusal for the pair. The first asserts it namescases 'big' and 'small'. The rewrite text they check is unchanged.test_validation.py::test_a_case_comparing_expressions_is_refused_as_undecidable, unchanged and passing.Gates
pixi run lint: all hooks pass.pixi run ci: 2601 passed; docs-build--strictno issues; render-tex and compile-tex 55 documents.Deliberately not done
examples/is unchanged; no test forced a change.