Skip to content

Commit 398eed8

Browse files
committed
Make 'Dependency.init' invalid and align Any/Invalid property
VersionRange has Invalid and Any while Dependency has invalid and any. One has to go, and it's going to be Dependency's. In addition, make sure that the 'init' state of Dependency is a known state.
1 parent 55e3ad4 commit 398eed8

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

source/dub/dependency.d

+11-6
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,19 @@ struct Dependency {
124124
// Shortcut to create >=0.0.0
125125
private enum ANY_IDENT = "*";
126126

127-
private Value m_value;
127+
private Value m_value = Value(VersionRange.Invalid);
128128
private bool m_optional;
129129
private bool m_default;
130130

131131
/// A Dependency, which matches every valid version.
132-
static @property Dependency any() @safe { return Dependency(VersionRange.Any); }
132+
public static immutable Dependency Any = Dependency(VersionRange.Any);
133133

134134
/// An invalid dependency (with no possible version matches).
135+
public static immutable Dependency Invalid = Dependency(VersionRange.Invalid);
136+
137+
deprecated("Use `Dependency.Any` instead")
138+
static @property Dependency any() @safe { return Dependency(VersionRange.Any); }
139+
deprecated("Use `Dependency.Invalid` instead")
135140
static @property Dependency invalid() @safe
136141
{
137142
return Dependency(VersionRange.Invalid);
@@ -510,11 +515,11 @@ struct Dependency {
510515
*/
511516
Dependency merge(ref const(Dependency) o) const @trusted {
512517
alias Merger = match!(
513-
(const NativePath a, const NativePath b) => a == b ? this : invalid,
518+
(const NativePath a, const NativePath b) => a == b ? this : Invalid,
514519
(const NativePath a, any ) => o,
515520
( any , const NativePath b) => this,
516521

517-
(const Repository a, const Repository b) => a.m_ref == b.m_ref ? this : invalid,
522+
(const Repository a, const Repository b) => a.m_ref == b.m_ref ? this : Invalid,
518523
(const Repository a, any ) => this,
519524
( any , const Repository b) => o,
520525

@@ -524,7 +529,7 @@ struct Dependency {
524529

525530
VersionRange copy = a;
526531
copy.merge(b);
527-
if (!copy.isValid()) return invalid;
532+
if (!copy.isValid()) return Invalid;
528533
return Dependency(copy);
529534
}
530535
);
@@ -682,7 +687,7 @@ unittest {
682687
assert(a.valid);
683688
assert(a.version_ == Version("~d2test"));
684689

685-
a = Dependency.any;
690+
a = Dependency.Any;
686691
assert(!a.optional);
687692
assert(a.valid);
688693
assertThrown(a.version_);

source/dub/project.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class Project {
483483
(VersionRange vers) {
484484
if (m_selections.hasSelectedVersion(basename)) {
485485
auto selver = m_selections.getSelectedVersion(basename);
486-
if (d.spec.merge(selver) == Dependency.invalid) {
486+
if (d.spec.merge(selver) == Dependency.Invalid) {
487487
logWarn(`Selected package %s@%s does not match ` ~
488488
`the dependency specification %s in ` ~
489489
`package %s. Need to "%s"?`,

source/dub/recipe/sdl.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private void parseDependency(Tag t, ref BuildSettingsTemplate bs, in PackageName
202202
auto pkg = expandPackageName(t.values[0].expect!string(t), name, t);
203203
enforceSDL(pkg !in bs.dependencies, "The dependency '"~pkg~"' is specified more than once.", t);
204204

205-
Dependency dep = Dependency.any;
205+
Dependency dep = Dependency.Any;
206206
auto attrs = t.attributes;
207207

208208
if ("path" in attrs) {

0 commit comments

Comments
 (0)