Repository navigation
Fix MultiConstraint upper bound inclusivity at the same version - #193
Merged
Seldaek merged 2 commits intoOct 22, 2026
Merged
Conversation
When two upper bounds share a version, extractBounds() relied on Bound::compareTo(), which orders same-version bounds as lower bounds (exclusive is higher). For upper bounds inclusive is higher, so the wrong one was kept: [< 1.0 || == 1.0] reported an exclusive upper bound of 1.0, excluding a version the constraint matches, and [< 1.0 <= 1.0] reported an inclusive one.
Member
|
Thanks. I expanded slightly on the checks and reduced the amount of version_compare calls because this code is on some hot paths, but looks good I think. |
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.
When two sub-constraints have upper bounds at the same version but with different inclusivity,
MultiConstraint::getUpperBound()keeps the wrong one:The disjunctive case gives a bound that leaves out a version the constraint matches. Through the parser this happens e.g. with
^1.0 || 2.0.0-dev(upper bound2.0.0.0-dev [exclusive]) or<=2.0-beta2 || <2.0-beta2.Cause:
extractBounds()usesBound::compareTo()for both bounds. For equal versions,compareTo()says the exclusive bound is higher, which is correct for lower bounds (> 1.0is tighter than>= 1.0) and is what the existing">" should take precedence ">="tests check. For upper bounds it's the other way round:<= 1.0is higher than< 1.0. So the upper-bound tie was always resolved backwards.The fix handles the same-version case for upper bounds in
extractBounds(): keep the exclusive bound when conjunctive and the inclusive one when disjunctive. Different versions still go throughcompareTo(), andBounditself is unchanged, so the lower-bound behaviour stays as it is.Tests: three cases added to the
bounds()provider inMultiConstraintTest, mirroring the existing lower-bound precedence cases.What was run (PHP 8.5.11, macOS):
vendor/bin/simple-phpunit --filter testBounds tests/Constraint/MultiConstraintTest.php: the 3 new cases fail without the change and pass with it.vendor/bin/simple-phpunitwithSYMFONY_DEPRECATIONS_HELPER=disabled: OK (2300 tests, 7115 assertions). Without that variable the run exits non-zero on master too, due to PHP 8.5ReflectionMethod::setAccessible()deprecations in existing tests.php -lon the changed files.php tests/vers/run-vers-tests.php <vers-spec>/tests --baseline=tests/vers/baseline.json: output identical on master and this branch. Both exit 1 because current vers-spec now passes>=5.0.3 >=4.2.1, which the baseline lists as a mismatch. That has nothing to do with this change.src/.Not run: the CI matrix on older PHP versions (the change only uses
version_compare()and existingBoundmethods), php-cs-fixer.