summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala1
-rw-r--r--src/test/scala/chiselTests/util/BitPatSpec.scala4
2 files changed, 5 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 88e46e3c..985d22da 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -23,6 +23,7 @@ object BitPat {
// If ? parsing is to be exposed, the return API needs further scrutiny
// (especially with things like mask polarity).
require(x.head == 'b', "BitPats must be in binary and be prefixed with 'b'")
+ require(x.length > 1, "BitPat width cannot be 0.")
var bits = BigInt(0)
var mask = BigInt(0)
var count = 0
diff --git a/src/test/scala/chiselTests/util/BitPatSpec.scala b/src/test/scala/chiselTests/util/BitPatSpec.scala
index a6c0acf7..ca8dd85c 100644
--- a/src/test/scala/chiselTests/util/BitPatSpec.scala
+++ b/src/test/scala/chiselTests/util/BitPatSpec.scala
@@ -14,4 +14,8 @@ class BitPatSpec extends AnyFlatSpec with Matchers {
val testPattern = "0" * 32 + "1" * 32 + "?" * 32 + "?01" * 32
BitPat("b" + testPattern).toString should be (s"BitPat($testPattern)")
}
+
+ it should "not fail if BitPat width is 0" in {
+ intercept[IllegalArgumentException]{BitPat("b")}
+ }
}