diff --git a/core/src/main/scala/chisel3/properties/Path.scala b/core/src/main/scala/chisel3/properties/Path.scala index cdfc17e2b9..f97a0284a4 100644 --- a/core/src/main/scala/chisel3/properties/Path.scala +++ b/core/src/main/scala/chisel3/properties/Path.scala @@ -106,8 +106,8 @@ object Path { /** Construct a Path from a target */ - def apply(target: IsMember): Path = apply(target, false) - def apply(target: IsMember, isMemberPath: Boolean): Path = { + def apply(target: => IsMember): Path = apply(target, false) + def apply(target: => IsMember, isMemberPath: Boolean): Path = { val _isMemberPath = isMemberPath // avoid name shadowing below new TargetPath { def toTarget(): IsMember = target diff --git a/src/test/scala/chiselTests/ToTargetSpec.scala b/src/test/scala/chiselTests/ToTargetSpec.scala index 608e83c9b3..3986825165 100644 --- a/src/test/scala/chiselTests/ToTargetSpec.scala +++ b/src/test/scala/chiselTests/ToTargetSpec.scala @@ -5,7 +5,7 @@ package chiselTests import chisel3._ import chisel3.properties.{Path, Property} import circt.stage.ChiselStage -import chisel3.experimental.hierarchy.{instantiable, public, Definition, Instance} +import chisel3.experimental.hierarchy.{instantiable, public, Definition, Instance, Instantiate} @instantiable class RelativeInnerModule extends RawModule { @@ -144,6 +144,20 @@ class RelativeSiblingsInstancesParent extends RawModule { } } +class PathFromInstanceToTarget extends RawModule { + @instantiable + class Hierarchy1 extends RawModule { + @instantiable + class Hierarchy2 extends RawModule { + val target = Instantiate(new RelativeInnerModule) + @public val path = IO(Output(Property[Path]())) + path := Property(Path(target.toTarget)) + } + val instance2 = Instantiate(new Hierarchy2) + } + val instance1 = Instantiate(new Hierarchy1) +} + class ToTargetSpec extends ChiselFlatSpec with Utils { var m: InstanceNameModule = _ @@ -290,4 +304,9 @@ class ToTargetSpec extends ChiselFlatSpec with Utils { e.getMessage should include("No common ancestor between") } + it should ("get correct Path from an Instance") in { + val chirrtl = ChiselStage.emitCHIRRTL(new PathFromInstanceToTarget) + chirrtl should include("OMInstanceTarget:~PathFromInstanceToTarget|Hierarchy2/target:RelativeInnerModule") + } + }