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: de7c9acb194b
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: 44b8bd29af09
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Dec 11, 2021

  1. Copy the full SHA
    44b8bd2 View commit details
Showing with 36 additions and 1 deletion.
  1. +13 −1 amaranth/hdl/ast.py
  2. +23 −0 tests/test_hdl_ast.py
14 changes: 13 additions & 1 deletion amaranth/hdl/ast.py
Original file line number Diff line number Diff line change
@@ -831,7 +831,14 @@ class Cat(Value):
"""
def __init__(self, *args, src_loc_at=0):
super().__init__(src_loc_at=src_loc_at)
self.parts = [Value.cast(v) for v in flatten(args)]
self.parts = []
for index, arg in enumerate(flatten(args)):
if isinstance(arg, int) and arg not in [0, 1]:
warnings.warn("Argument #{} of Cat() is a bare integer {} used in bit vector "
"context; consider specifying explicit width using C({}, {}) instead"
.format(index + 1, arg, arg, bits_for(arg)),
SyntaxWarning, stacklevel=2 + src_loc_at)
self.parts.append(Value.cast(arg))

def shape(self):
return Shape(sum(len(part) for part in self.parts))
@@ -880,6 +887,11 @@ def __init__(self, value, count, *, src_loc_at=0):
.format(count))

super().__init__(src_loc_at=src_loc_at)
if isinstance(value, int) and value not in [0, 1]:
warnings.warn("Value argument of Repl() is a bare integer {} used in bit vector "
"context; consider specifying explicit width using C({}, {}) instead"
.format(value, value, bits_for(value)),
SyntaxWarning, stacklevel=2 + src_loc_at)
self.value = Value.cast(value)
self.count = count

23 changes: 23 additions & 0 deletions tests/test_hdl_ast.py
Original file line number Diff line number Diff line change
@@ -746,6 +746,17 @@ def test_str_wrong(self):
r"^Object 'foo' cannot be converted to an Amaranth value$"):
Cat("foo")

def test_int_01(self):
with warnings.catch_warnings():
warnings.filterwarnings(action="error", category=SyntaxWarning)
Cat(0, 1, 1, 0)

def test_int_wrong(self):
with self.assertWarnsRegex(SyntaxWarning,
r"^Argument #1 of Cat\(\) is a bare integer 2 used in bit vector context; "
r"consider specifying explicit width using C\(2, 2\) instead$"):
Cat(2)


class ReplTestCase(FHDLTestCase):
def test_shape(self):
@@ -769,6 +780,18 @@ def test_cast(self):
r = Repl(0, 3)
self.assertEqual(repr(r), "(repl (const 1'd0) 3)")

def test_int_01(self):
with warnings.catch_warnings():
warnings.filterwarnings(action="error", category=SyntaxWarning)
Repl(0, 3)
Repl(1, 3)

def test_int_wrong(self):
with self.assertWarnsRegex(SyntaxWarning,
r"^Value argument of Repl\(\) is a bare integer 2 used in bit vector context; "
r"consider specifying explicit width using C\(2, 2\) instead$"):
Repl(2, 3)


class ArrayTestCase(FHDLTestCase):
def test_acts_like_array(self):