From 5024b706f0638cf3ebbe634b658fa016941e72ac Mon Sep 17 00:00:00 2001 From: Adam Izraelevitz Date: Mon, 25 Oct 2021 16:55:23 -0700 Subject: Bugfix: fix isACloneOf (#2205) --- core/src/main/scala/chisel3/Module.scala | 13 ++++++++++++- .../scala/chisel3/experimental/hierarchy/Lookupable.scala | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/chisel3/Module.scala b/core/src/main/scala/chisel3/Module.scala index 56dce4d5..1ae65969 100644 --- a/core/src/main/scala/chisel3/Module.scala +++ b/core/src/main/scala/chisel3/Module.scala @@ -193,7 +193,18 @@ package internal { // Underlying object of which this is a clone of val _proto: T def getProto: T = _proto - def isACloneOf(a: Any): Boolean = this == a || _proto == a + + /** Determines whether another object is a clone of the same underlying proto + * + * @param a + */ + def hasSameProto(a: Any): Boolean = { + val aProto = a match { + case x: IsClone[BaseModule] => x._proto + case o => o + } + this == aProto || _proto == aProto + } } // Private internal class to serve as a _parent for Data in cloned ports diff --git a/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala b/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala index b9617723..2242c1c4 100644 --- a/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala +++ b/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala @@ -217,7 +217,7 @@ private[chisel3] object Lookupable { } (m, context) match { case (c, ctx) if ctx == c => Left(c) - case (c, ctx: IsClone[_]) if ctx.isACloneOf(c) => Right(ctx.asInstanceOf[IsClone[A]]) + case (c, ctx: IsClone[_]) if ctx.hasSameProto(c) => Right(ctx.asInstanceOf[IsClone[A]]) case (c, ctx) if c._parent.isEmpty => Left(c) case (_, _) => cloneModuleToContext(Left(m._parent.get), context) match { -- cgit v1.2.3