Skip to content

Commit ef2e9fa

Browse files
committed
hdl.ast: Value.matches() with no arguments should return C(1).
The behavior of the following must be always the same: - `with m.Switch(v): with m.Case(*pats):` - `with m.If(v.matches(*pats)):`
1 parent 9aeb223 commit ef2e9fa

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

amaranth/hdl/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def matches(self, *patterns):
442442
continue
443443
matches.append(self == pattern)
444444
if not matches:
445-
return Const(0)
445+
return Const(1)
446446
elif len(matches) == 1:
447447
return matches[0]
448448
else:

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Language changes
3434
* Added: :meth:`Value.matches` and ``with m.Case():`` accept any constant-castable objects. (`RFC 4`_)
3535
* Changed: :meth:`Value.cast` casts :class:`ValueCastable` objects recursively.
3636
* Changed: :meth:`Value.cast` treats instances of classes derived from both :class:`enum.Enum` and :class:`int` (including :class:`enum.IntEnum`) as enumerations rather than integers.
37+
* Changed: ``Value.matches()`` with an empty list of patterns returns ``Const(1)`` rather than ``Const(0)``, to match ``with m.Case():``.
3738
* Changed: :class:`Cat` accepts instances of classes derived from both :class:`enum.Enum` and :class:`int` (including :class:`enum.IntEnum`) without warning.
3839
* Deprecated: :meth:`Const.normalize`. (`RFC 5`_)
3940
* Removed: (deprecated in 0.1) casting of :class:`Shape` to and from a ``(width, signed)`` tuple.

tests/test_hdl_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def test_xor_value(self):
599599

600600
def test_matches(self):
601601
s = Signal(4)
602-
self.assertRepr(s.matches(), "(const 1'd0)")
602+
self.assertRepr(s.matches(), "(const 1'd1)")
603603
self.assertRepr(s.matches(1), """
604604
(== (sig s) (const 1'd1))
605605
""")

0 commit comments

Comments
 (0)