diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index ce222c5ea2f..a33f7e08f70 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -373,6 +373,9 @@ def test_intersect_with_containment(): check_intersection('1.6:1.6.5', ':1.6.5', '1.6') check_intersection('1.6:1.6.5', '1.6', ':1.6.5') + check_intersection('11.2', '11', '11.2') + check_intersection('11.2', '11.2', '11') + def test_union_with_containment(): check_union(':1.6', '1.6.5', ':1.6') diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py index 321a03efc7c..82c0afd53ec 100644 --- a/lib/spack/spack/version.py +++ b/lib/spack/spack/version.py @@ -372,8 +372,10 @@ def union(self, other): @coerced def intersection(self, other): - if self == other: + if self in other: # also covers `self == other` return self + elif other in self: + return other else: return VersionList()