From c2de91d1d94a403fdeac8d3f45b2d67392cc4d9b Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Tue, 11 Dec 2018 22:20:13 -0500 Subject: Remove side effect from DiGraph summation This fixes a bug where DiGraph summation (using the `+` operator) would mutate the DiGraph. This occurred because the underlying edges set was not being cloned. This is fixed to explicitly clone the underlying edges set. Signed-off-by: Schuyler Eldridge --- src/main/scala/firrtl/graph/DiGraph.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/scala/firrtl/graph/DiGraph.scala b/src/main/scala/firrtl/graph/DiGraph.scala index 1d15d505..9cfcad52 100644 --- a/src/main/scala/firrtl/graph/DiGraph.scala +++ b/src/main/scala/firrtl/graph/DiGraph.scala @@ -349,8 +349,8 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link * @return a DiGraph[T] containing all vertices and edges of each graph */ def +(that: DiGraph[T]): DiGraph[T] = { - val eprime = edges.clone - that.edges.map({ case (k, v) => eprime.getOrElseUpdate(k, new LinkedHashSet[T]) ++= v }) + val eprime = edges.map({ case (k, v) => (k, v.clone) }) + that.edges.foreach({ case (k, v) => eprime.getOrElseUpdate(k, new LinkedHashSet[T]) ++= v }) new DiGraph(eprime) } } -- cgit v1.2.3