Skip to content

Commit d7630dc

Browse files
Fix DataMirror.internal.chiselTypeClone to preserve Scala type (#3553) (#3555)
(cherry picked from commit e6c07b3) Co-authored-by: Jack Koenig <koenig@sifive.com>
1 parent a4cbe9f commit d7630dc

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

core/src/main/scala/chisel3/reflect/DataMirror.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ object DataMirror {
174174
object internal {
175175
def isSynthesizable(target: Data): Boolean = target.isSynthesizable
176176
// For those odd cases where you need to care about object reference and uniqueness
177-
def chiselTypeClone[T <: Data](target: Data): T = {
178-
target.cloneTypeFull.asInstanceOf[T]
177+
def chiselTypeClone[T <: Data](target: T): T = {
178+
target.cloneTypeFull
179179
}
180180
}
181181

src/test/scala/chiselTests/reflect/DataMirrorSpec.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,15 @@ class DataMirrorSpec extends ChiselFlatSpec {
111111
it should "not support name guesses for non-hardware" in {
112112
an[ExpectedHardwareException] should be thrownBy DataMirror.queryNameGuess(UInt(8.W))
113113
}
114+
115+
"chiselTypeClone" should "preserve Scala type information" in {
116+
class MyModule extends Module {
117+
val in = IO(Input(UInt(8.W)))
118+
val out = IO(Output(DataMirror.internal.chiselTypeClone(in)))
119+
// The connection checks the types
120+
out :#= in
121+
}
122+
ChiselStage.emitCHIRRTL(new MyModule)
123+
}
124+
114125
}

0 commit comments

Comments
 (0)