hdl.dsl: reword m.If(~True) warning to be more clear.
authorwhitequark <cz@m-labs.hk>
Sat, 3 Aug 2019 18:52:24 +0000 (18:52 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 3 Aug 2019 18:52:24 +0000 (18:52 +0000)
Before this commit, it only suggested one thing (silencing it) and
that's wrong almost all of the time, so suggest the right thing
instead.

nmigen/hdl/dsl.py
nmigen/test/test_hdl_dsl.py

index e090b0967fc16e9ba299c2a8fcac55ae5b3bad2b..9a7d598abf51173b56f79e15c50501dd5ca0a3e0 100644 (file)
@@ -171,8 +171,9 @@ class Module(_ModuleBuilderRoot, Elaboratable):
         if sign:
             warnings.warn("Signed values in If/Elif conditions usually result from inverting "
                           "Python booleans with ~, which leads to unexpected results: ~True is "
-                          "-2, which is truthful. "
-                          "(Silence this warning with `m.If(x)` → `m.If(x.bool())`.)",
+                          "-2, which is truthful. Replace `~flag` with `not flag`. (If this is "
+                          "a false positive, silence this warning with "
+                          "`m.If(x)` → `m.If(x.bool())`.)",
                           SyntaxWarning, stacklevel=4)
         return cond
 
index 0ff7fefe932484649e4346558d8004d6686b9f48..1da5a6a2b2366d1032a1420ed7cecb2c6ca1cce2 100644 (file)
@@ -273,7 +273,8 @@ class DSLTestCase(FHDLTestCase):
         with self.assertWarns(SyntaxWarning,
                 msg="Signed values in If/Elif conditions usually result from inverting Python "
                     "booleans with ~, which leads to unexpected results: ~True is -2, which is "
-                    "truthful. (Silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
+                    "truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
+                    "silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
             with m.If(~True):
                 pass
 
@@ -284,7 +285,8 @@ class DSLTestCase(FHDLTestCase):
         with self.assertWarns(SyntaxWarning,
                 msg="Signed values in If/Elif conditions usually result from inverting Python "
                     "booleans with ~, which leads to unexpected results: ~True is -2, which is "
-                    "truthful. (Silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
+                    "truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
+                    "silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
             with m.Elif(~True):
                 pass