diff --git a/core/src/main/scala/chisel3/internal/firrtl/IR.scala b/core/src/main/scala/chisel3/internal/firrtl/IR.scala index 105ae4feccc..64e15f5d384 100644 --- a/core/src/main/scala/chisel3/internal/firrtl/IR.scala +++ b/core/src/main/scala/chisel3/internal/firrtl/IR.scala @@ -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 { diff --git a/src/test/scala/chiselTests/UIntOps.scala b/src/test/scala/chiselTests/UIntOps.scala index 5d6bd8ccca9..73fbf5f33bb 100644 --- a/src/test/scala/chiselTests/UIntOps.scala +++ b/src/test/scala/chiselTests/UIntOps.scala @@ -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") + } }