Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide require message for negative widths #4008

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,7 +36,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 @@ -602,4 +602,9 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers with Utils with ShiftRigh
withOptFirrtl should include(line)
}
}

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")
}
}
Loading