"""
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))
.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
r"^Object 'foo' cannot be converted to an nMigen 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):
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):