diff options
| author | Adam Izraelevitz | 2021-09-15 11:49:29 -0700 |
|---|---|---|
| committer | GitHub | 2021-09-15 18:49:29 +0000 |
| commit | 1ae18008e18dfe20983a6ba3b2b950f66245e69b (patch) | |
| tree | f17d96d733e54eee5c8dd1551430ac874e10160d | |
| parent | c66f0ed24366f8ce0e20a5a420589b8ae01aba77 (diff) | |
Fix higher-kinded types for autoclonetype (#2121)
| -rw-r--r-- | plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala | 6 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/AutoClonetypeSpec.scala | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala b/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala index 96851e95..5fe63991 100644 --- a/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala +++ b/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala @@ -108,8 +108,10 @@ private[plugin] class BundleComponent(val global: Global, arguments: ChiselPlugi if (isData(vp.symbol)) cloneTypeFull(select) else select }) - val ttpe = Ident(bundle.symbol) - val neww = localTyper.typed(New(ttpe, conArgs)) + val tparamList = bundle.tparams.map{ t => Ident(t.symbol) } + val ttpe = if(tparamList.nonEmpty) AppliedTypeTree(Ident(bundle.symbol), tparamList) else Ident(bundle.symbol) + val newUntyped = New(ttpe, conArgs) + val neww = localTyper.typed(newUntyped) // Create the symbol for the method and have it be associated with the Bundle class val cloneTypeSym = bundle.symbol.newMethod(TermName("_cloneTypeImpl"), bundle.symbol.pos.focus, Flag.OVERRIDE | Flag.PROTECTED) diff --git a/src/test/scala/chiselTests/AutoClonetypeSpec.scala b/src/test/scala/chiselTests/AutoClonetypeSpec.scala index 57e00e99..fcbc4785 100644 --- a/src/test/scala/chiselTests/AutoClonetypeSpec.scala +++ b/src/test/scala/chiselTests/AutoClonetypeSpec.scala @@ -348,5 +348,18 @@ class AutoClonetypeSpec extends ChiselFlatSpec with Utils { elaborate(new MyModule(UInt(8.W))) } + it should "work for higher-kinded types" in { + class DataGen[T <: Data](gen: T) { + def newType: T = gen.cloneType + } + class MyBundle[A <: Data, B <: DataGen[A]](gen: B) extends Bundle { + val foo = gen.newType + } + class MyModule extends MultiIOModule { + val io = IO(Output(new MyBundle[UInt, DataGen[UInt]](new DataGen(UInt(3.W))))) + io.foo := 0.U + } + elaborate(new MyModule) + } } } |
