Skip to content

Commit

Permalink
Provide require message for negative widths (backport #4008) (#4010)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mergify[bot] and jackkoenig authored Apr 17, 2024
1 parent 91edc11 commit edb3616
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Width.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sealed case class UnknownWidth() extends Width {
}

sealed case class KnownWidth(value: Int) extends Width {
require(value >= 0)
require(value >= 0, s"Widths must be non-negative, got $value")
def known: Boolean = true
def get: Int = value
def op(that: Width, f: (W, W) => W): Width = that match {
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/chiselTests/UIntOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,9 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers with Utils {
chirrtl should include("connect y, a")
chirrtl should include("connect z, b")
}

property("UInts with negative widths should have a decent error message") {
val e = the[IllegalArgumentException] thrownBy (UInt(-8.W))
e.getMessage should include("Widths must be non-negative, got -8")
}
}

0 comments on commit edb3616

Please sign in to comment.