Skip to content

Commit edb3616

Browse files
Provide require message for negative widths (backport #4008) (#4010)
* Provide require message for negative widths (#4008) (cherry picked from commit 751a4cf) # Conflicts: # src/test/scala/chiselTests/UIntOps.scala * Resolve backport conflicts --------- Co-authored-by: Jack Koenig <[email protected]>
1 parent 91edc11 commit edb3616

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

core/src/main/scala/chisel3/Width.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sealed case class UnknownWidth() extends Width {
3030
}
3131

3232
sealed case class KnownWidth(value: Int) extends Width {
33-
require(value >= 0)
33+
require(value >= 0, s"Widths must be non-negative, got $value")
3434
def known: Boolean = true
3535
def get: Int = value
3636
def op(that: Width, f: (W, W) => W): Width = that match {

src/test/scala/chiselTests/UIntOps.scala

+5
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,9 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers with Utils {
485485
chirrtl should include("connect y, a")
486486
chirrtl should include("connect z, b")
487487
}
488+
489+
property("UInts with negative widths should have a decent error message") {
490+
val e = the[IllegalArgumentException] thrownBy (UInt(-8.W))
491+
e.getMessage should include("Widths must be non-negative, got -8")
492+
}
488493
}

0 commit comments

Comments
 (0)