Skip to content

Commit

Permalink
Provide require message for negative widths (backport #4008) (#4009)
Browse files Browse the repository at this point in the history
* Provide require message for negative widths (#4008)

(cherry picked from commit 751a4cf)

# Conflicts:
#	core/src/main/scala/chisel3/Width.scala

* Resolve backport conflicts

---------

Co-authored-by: Jack Koenig <koenig@sifive.com>
  • Loading branch information
mergify[bot] and jackkoenig authored Apr 17, 2024
1 parent daede76 commit b5f000f
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/internal/firrtl/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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 @@ -479,4 +479,9 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers with Utils {
chirrtl should include("y <= a")
chirrtl should include("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 b5f000f

Please sign in to comment.