Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a9da9efe5bdd
Choose a base ref
...
head repository: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 687d3a3df74b
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jan 31, 2020

  1. Copy the full SHA
    687d3a3 View commit details
Showing with 14 additions and 0 deletions.
  1. +7 −0 nmigen/hdl/dsl.py
  2. +7 −0 nmigen/test/test_hdl_dsl.py
7 changes: 7 additions & 0 deletions nmigen/hdl/dsl.py
Original file line number Diff line number Diff line change
@@ -309,6 +309,13 @@ def Case(self, *patterns):
.format(pattern, len(switch_data["test"])),
SyntaxWarning, stacklevel=3)
continue
if isinstance(pattern, Enum) and bits_for(pattern.value) > len(switch_data["test"]):
warnings.warn("Case pattern '{:b}' ({}.{}) is wider than switch value "
"(which has width {}); comparison will never be true"
.format(pattern.value, pattern.__class__.__name__, pattern.name,
len(switch_data["test"])),
SyntaxWarning, stacklevel=3)
continue
new_patterns = (*new_patterns, pattern)
try:
_outer_case, self._statements = self._statements, []
7 changes: 7 additions & 0 deletions nmigen/test/test_hdl_dsl.py
Original file line number Diff line number Diff line change
@@ -400,6 +400,8 @@ class Color(Enum):
""")

def test_Case_width_wrong(self):
class Color(Enum):
RED = 0b10101010
m = Module()
with m.Switch(self.w1):
with self.assertRaises(SyntaxError,
@@ -411,6 +413,11 @@ def test_Case_width_wrong(self):
"comparison will never be true"):
with m.Case(0b10110):
pass
with self.assertWarns(SyntaxWarning,
msg="Case pattern '10101010' (Color.RED) is wider than switch value "
"(which has width 4); comparison will never be true"):
with m.Case(Color.RED):
pass
self.assertRepr(m._statements, """
(
(switch (sig w1) )