Skip to content

Commit

Permalink
Fix DataMirror.internal.chiselTypeClone to preserve Scala type (#3553)
Browse files Browse the repository at this point in the history
(cherry picked from commit e6c07b3)
  • Loading branch information
jackkoenig authored and mergify[bot] committed Sep 26, 2023
1 parent afb75de commit 6c5013b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/chisel3/reflect/DataMirror.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ object DataMirror {
object internal {
def isSynthesizable(target: Data): Boolean = target.isSynthesizable
// For those odd cases where you need to care about object reference and uniqueness
def chiselTypeClone[T <: Data](target: Data): T = {
target.cloneTypeFull.asInstanceOf[T]
def chiselTypeClone[T <: Data](target: T): T = {
target.cloneTypeFull
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/scala/chiselTests/reflect/DataMirrorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,15 @@ class DataMirrorSpec extends ChiselFlatSpec {
it should "not support name guesses for non-hardware" in {
an[ExpectedHardwareException] should be thrownBy DataMirror.queryNameGuess(UInt(8.W))
}

"chiselTypeClone" should "preserve Scala type information" in {
class MyModule extends Module {
val in = IO(Input(UInt(8.W)))
val out = IO(Output(DataMirror.internal.chiselTypeClone(in)))
// The connection checks the types
out :#= in
}
ChiselStage.emitCHIRRTL(new MyModule)
}

}

0 comments on commit 6c5013b

Please sign in to comment.