From 109b4d8629beb62f7516ca14295258b4131f5849 Mon Sep 17 00:00:00 2001 From: Chick Markley Date: Fri, 17 Dec 2021 10:13:54 -0800 Subject: Improve exception message for aliased bundle fields (#2304) - Shows groups of field names that share a common id (i.e. aliased) - Show, as much as possible, them in the order that fields appear in bundle - Updated BundleSpec's relevant tests Co-authored-by: Megan Wachs Co-authored-by: Jack Koenig --- core/src/main/scala/chisel3/Aggregate.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/main/scala/chisel3/Aggregate.scala b/core/src/main/scala/chisel3/Aggregate.scala index 600e2d11..db354e1f 100644 --- a/core/src/main/scala/chisel3/Aggregate.scala +++ b/core/src/main/scala/chisel3/Aggregate.scala @@ -29,7 +29,26 @@ sealed abstract class Aggregate extends Data { val resolvedDirection = SpecifiedDirection.fromParent(parentDirection, specifiedDirection) val duplicates = getElements.groupBy(identity).collect { case (x, elts) if elts.size > 1 => x } if (!duplicates.isEmpty) { - throw new AliasedAggregateFieldException(s"Aggregate $this contains aliased fields $duplicates") + this match { + case b: Record => + // show groups of names of fields with duplicate id's + // The sorts make the displayed order of fields deterministic and matching the order of occurrence in the Bundle. + // It's a bit convoluted but happens rarely and makes the error message easier to understand + val dupNames = duplicates.toSeq.sortBy(_._id).map { duplicate => + b.elements + .collect { case x if x._2._id == duplicate._id => x } + .toSeq.sortBy(_._2._id) + .map(_._1).reverse + .mkString("(", ",", ")") + }.mkString(",") + throw new AliasedAggregateFieldException( + s"${b.className} contains aliased fields named ${dupNames}" + ) + case _ => + throw new AliasedAggregateFieldException( + s"Aggregate ${this.getClass} contains aliased fields $duplicates ${duplicates.mkString(",")}" + ) + } } for (child <- getElements) { child.bind(ChildBinding(this), resolvedDirection) -- cgit v1.2.3