Skip to content

Commit b1ce801

Browse files
committed
fix: a range that matches none of a package's pre-release keys names the pin that works
A package whose only orderable keys are pre-releases (compat.glad publishes 0.0.0-651a425 alone, compat.tray 0.0.0-8dd1358) can never be reached by a range: a range sees a pre-release only when it names one at the same numbers. `"*"` or `"^0.0"` against such a package failed with constraint '*' matches none of: [0.0.0-651a425] and nothing more. The exact-pin hint was given only for unorderable keys, while these keys are orderable and took the plain branch. When every orderable key is a pre-release, the error now says why the range misses and offers the exact pin, with the highest pre-release as its value: These keys are pre-releases, which a range matches only when it names a pre-release of the same version — pin one exactly: acme.pre = "0.0.0-651a425" A package that also publishes a release is unchanged: a range can reach the release, so a miss there is an ordinary one. e2e 196 covers `*` and `^0.0` over one pre-release key, the highest of several being offered, the offered pin resolving, and no hint when a release is published. docs/05 (both languages) states the rule. Closes #370.
1 parent 304487b commit b1ce801

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎docs/05-dependencies.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ and `"0.0"` is `>= 0.0.0, < 0.1.0` (before 2026.10.31.1 both matched 0.0.0
128128
alone). The dependency conflict check and the address check of `--locked` read
129129
requirements the same way.
130130

131+
A range matches a pre-release key (`1.0.0-rc.1`) only when it names a
132+
pre-release of the same version, so `*` or `^0.0` reaches none of the keys of a
133+
package that publishes only pre-releases (`compat.glad` publishes
134+
`0.0.0-651a425`). The error then names the exact pin to write.
135+
131136
### `visibility` — whether a dependency's usage crosses this package's own boundary
132137

133138
```toml

‎docs/zh/05-dependencies.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ qux = ">=1.0, <2.0" # Range combination
115115
不带运算符的部分写法同样按 caret 的通配规则:`"0"` 为 `>= 0.0.0, < 1.0.0`,`"0.0"` 为 `>= 0.0.0, < 0.1.0`(2026.10.31.1 之前
116116
两者都只匹配 0.0.0)。依赖冲突检查与 `--locked` 的地址核对以同样的方式读取要求。
117117

118+
范围只在写出同一版本的预发布时才匹配预发布键(`1.0.0-rc.1`),因此对只发布预发布键的包
119+
(`compat.glad` 只发布 `0.0.0-651a425`),`*` 或 `^0.0` 一个键也够不着;这时的错误会给出应写的精确版本。
120+
118121
### `visibility` —— 一个依赖的用法是否跨越本包自己的边界
119122

120123
```toml

‎src/pm/resolver.cppm‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ resolve_semver(std::string_view ns, std::string_view shortName,
228228
auto msg = std::format(
229229
"dependency '{}': constraint '{}' matches none of: [{}]",
230230
qname, constraint, join(literals));
231+
// A range sees a pre-release only when it names one at the same numbers,
232+
// so when every orderable key is a pre-release (`compat.glad` publishes
233+
// `0.0.0-651a425` alone) no `*` or `^0.0` can reach any of them: the
234+
// remedy is the same exact pin as for an unorderable key (mcpp#370).
235+
if (std::ranges::all_of(parsed, &vr::Version::isPrerelease)) {
236+
const auto highest = std::ranges::max_element(parsed) - parsed.begin();
237+
msg += std::format(
238+
"\n These keys are pre-releases, which a range matches only when "
239+
"it names a pre-release of the same version — pin one exactly:"
240+
"\n {} = \"{}\"",
241+
qname, literals[static_cast<std::size_t>(highest)]);
242+
}
231243
if (!unorderable.empty())
232244
msg += std::format("\n (also published, but not orderable: [{}]){}",
233245
join(unorderable), pin_hint(unorderable));

‎tests/e2e/196_version_identity_and_lock.sh‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ mk_pkg jdk '{ ["latest"] = { ref = "25.0.4.7.1" },
5454
# khistory's shape: the only real release has an unorderable key.
5555
mk_pkg kh '{ ["latest"] = { ref = "pre-v0.0.5" },
5656
["pre-v0.0.5"] = { url = "u", sha256 = "0" } }'
57+
# compat.glad's shape: the only key is a pre-release (mcpp#370).
58+
mk_pkg pre '{ ["0.0.0-651a425"] = { url = "u", sha256 = "0" } }'
59+
# Only pre-releases, more than one: the pin offered is the highest.
60+
mk_pkg rc '{ ["1.0.0-rc.1"] = { url = "u", sha256 = "0" },
61+
["1.0.0-rc.2"] = { url = "u", sha256 = "0" } }'
5762
# jdk-temurin's shape, but with two REAL entries: a genuine precedence tie.
5863
mk_pkg tie '{ ["1.0.0+a"] = { url = "u", sha256 = "0" },
5964
["1.0.0+b"] = { url = "u", sha256 = "0" } }'
@@ -139,6 +144,39 @@ use_dep kh '=pre-v0.0.5'
139144
grep -qE 'invalid version constraint|not ordered versions' b5b.log \
140145
&& fail "'=<unorderable key>' must resolve to that key" b5b.log
141146

147+
# ── 4b. Only pre-releases: no range reaches them, so the error says what does ──
148+
# The keys are orderable, so this is not the unorderable branch above, but a
149+
# range still sees a pre-release only when it names one (mcpp#370).
150+
for c in '*' '^0.0'; do
151+
use_dep pre "$c"
152+
"$MCPP" build > b4c.log 2>&1 && fail "'$c' must not reach a pre-release" b4c.log
153+
grep -q 'matches none of' b4c.log || fail "expected '$c' to match none" b4c.log
154+
grep -q 'These keys are pre-releases' b4c.log \
155+
|| fail "expected the error to say why '$c' matches none" b4c.log
156+
grep -q 'acme.pre = "0.0.0-651a425"' b4c.log \
157+
|| fail "the error for '$c' must show the exact pin that works" b4c.log
158+
done
159+
160+
use_dep rc '^1.0'
161+
"$MCPP" build > b4d.log 2>&1 && fail "'^1.0' must not reach a pre-release" b4d.log
162+
grep -q 'acme.rc = "1.0.0-rc.2"' b4d.log \
163+
|| fail "the pin offered must be the highest pre-release" b4d.log
164+
165+
# The pin offered resolves (and fails later, at install, for want of a payload).
166+
use_dep pre '0.0.0-651a425'
167+
"$MCPP" build > b4f.log 2>&1 && fail "expected the unseeded payload to fail" b4f.log
168+
grep -q 'matches none of' b4f.log \
169+
&& fail "the exact pre-release pin the error offers must resolve" b4f.log
170+
grep -q '0\.0\.0-651a425' b4f.log || fail "the exact key must be addressed literally" b4f.log
171+
172+
# A release among the keys can be reached by a range, so a miss there is an
173+
# ordinary one and carries no pin.
174+
use_dep im '^2'
175+
"$MCPP" build > b4e.log 2>&1 && fail "'^2' must match none of im's keys" b4e.log
176+
grep -q 'matches none of' b4e.log || fail "expected '^2' to match none" b4e.log
177+
grep -q 'pre-releases' b4e.log \
178+
&& fail "a package that publishes a release must not get the pre-release pin" b4e.log
179+
142180
# ── 5. A genuine precedence tie is refused, not guessed ───────────────────
143181
use_dep tie '^1.0'
144182
"$MCPP" build > b6.log 2>&1 && fail "a tie must not silently pick one" b6.log

0 commit comments

Comments
 (0)