aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchuyler Eldridge2018-12-11 22:20:13 -0500
committerSchuyler Eldridge2018-12-12 00:55:50 -0500
commitc2de91d1d94a403fdeac8d3f45b2d67392cc4d9b (patch)
tree15fdb4b390adf24d1604a3d57f7da8ff13bacfa5
parent50ba95fe05cc348496425733554be5fc7d797de1 (diff)
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 <schuyler.eldridge@ibm.com>
-rw-r--r--src/main/scala/firrtl/graph/DiGraph.scala4
1 files changed, 2 insertions, 2 deletions
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)
}
}