Skip to content

Commit 3b89375

Browse files
committed
Fix semantic of variant intersection
1 parent 9a90d9f commit 3b89375

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

lib/spack/spack/test/spec_semantics.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,31 +319,28 @@ def test_constraining_abstract_specs_with_empty_intersection(self, lhs, rhs):
319319
rhs.constrain(lhs)
320320

321321
@pytest.mark.parametrize(
322-
"lhs,rhs",
322+
"lhs,rhs,intersection_expected",
323323
[
324-
("mpich", "mpich +foo"),
325-
("mpich", "mpich~foo"),
326-
("mpich", "mpich foo=1"),
327-
("mpich", "mpich++foo"),
328-
("mpich", "mpich~~foo"),
329-
("mpich", "mpich foo==1"),
324+
("mpich", "mpich +foo", True),
325+
("mpich", "mpich~foo", True),
326+
("mpich", "mpich foo=1", True),
327+
("mpich", "mpich++foo", True),
328+
("mpich", "mpich~~foo", True),
329+
("mpich", "mpich foo==1", True),
330330
# Flags semantics is currently different from other variant
331-
pytest.param("mpich", 'mpich cppflags="-O3"', marks=pytest.mark.xfail),
332-
pytest.param(
333-
"multivalue-variant foo=bar", "multivalue-variant +foo", marks=pytest.mark.xfail
334-
),
335-
pytest.param(
336-
"multivalue-variant foo=bar", "multivalue-variant ~foo", marks=pytest.mark.xfail
337-
),
331+
# ("mpich", 'mpich cppflags="-O3"', False),
332+
("multivalue-variant foo=bar", "multivalue-variant +foo", False),
333+
("multivalue-variant foo=bar", "multivalue-variant ~foo", False),
334+
("multivalue-variant fee=bar", "multivalue-variant fee=baz", False),
338335
],
339336
)
340337
def test_concrete_specs_which_do_not_satisfy_abstract(
341-
self, lhs, rhs, default_mock_concretization
338+
self, lhs, rhs, intersection_expected, default_mock_concretization
342339
):
343340
lhs, rhs = default_mock_concretization(lhs), Spec(rhs)
344341

345-
assert lhs.intersects(rhs)
346-
assert rhs.intersects(lhs)
342+
assert lhs.intersects(rhs) is intersection_expected
343+
assert rhs.intersects(lhs) is intersection_expected
347344
assert not lhs.satisfies(rhs)
348345
assert not rhs.satisfies(lhs)
349346

lib/spack/spack/variant.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ def satisfies(self, other):
348348
# (`foo=bar` will never satisfy `baz=bar`)
349349
return other.name == self.name
350350

351-
@implicit_variant_conversion
352351
def intersects(self, other):
353352
"""Returns True if there are variant matching both self and other, False otherwise."""
353+
if isinstance(other, (SingleValuedVariant, BoolValuedVariant)):
354+
return other.intersects(self)
354355
return other.name == self.name
355356

356357
def compatible(self, other):

0 commit comments

Comments
 (0)