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

Fix getWidth on empty Vecs; add test #561

Merged
merged 1 commit into from
Mar 24, 2017
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 chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sealed abstract class Aggregate extends Data {
*/
def getElements: Seq[Data]

private[core] def width: Width = getElements.map(_.width).reduce(_ + _)
private[core] def width: Width = getElements.map(_.width).foldLeft(0.W)(_ + _)
private[core] def legacyConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
pushCommand(BulkConnect(sourceInfo, this.lref, that.lref))

Expand Down
9 changes: 9 additions & 0 deletions src/test/scala/chiselTests/Vec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class OneBitUnitRegVecTester extends BasicTester {
stop()
}

class ZeroEntryVecTester extends BasicTester {
require(Vec(0, Bool()).getWidth == 0)
stop()
}

class VecSpec extends ChiselPropSpec {
// Disable shrinking on error.
implicit val noShrinkListVal = Shrink[List[Int]](_ => Stream.empty)
Expand Down Expand Up @@ -187,4 +192,8 @@ class VecSpec extends ChiselPropSpec {
property("A Reg of a Vec of a single 1 bit element should compile and work") {
assertTesterPasses{ new OneBitUnitRegVecTester }
}

property("A Vec with zero entries should compile and have zero width") {
assertTesterPasses{ new ZeroEntryVecTester }
}
}