Skip to content

Commit f2267d7

Browse files
committed
Get things working with this.type
1 parent 8c4aaf5 commit f2267d7

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

core/src/main/scala/chisel3/AggregateImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private[chisel3] abstract class VecImpl[T <: Data] private[chisel3] (gen: => T,
543543
requireIsChiselType(this, "vec literal constructor model")
544544
checkLiteralConstruction()
545545

546-
val clone = cloneType
546+
val clone: this.type = this.cloneType
547547
val cloneFields = getRecursiveFields(clone, "(vec root)").toMap
548548

549549
// Create the Vec literal binding from litArgs of arguments
@@ -833,7 +833,7 @@ private[chisel3] trait RecordImpl extends AggregateImpl { thiz: Record =>
833833
}
834834

835835
override def cloneType: this.type = {
836-
val clone = _cloneTypeImpl.asInstanceOf[this.type]
836+
val clone: this.type = _cloneTypeImpl.asInstanceOf[this.type]
837837
checkClone(clone)
838838
clone
839839
}
@@ -956,7 +956,7 @@ private[chisel3] trait RecordImpl extends AggregateImpl { thiz: Record =>
956956
private[chisel3] def _makeLit(elems: (this.type => (Data, Data))*)(implicit sourceInfo: SourceInfo): this.type = {
957957

958958
requireIsChiselType(this, "bundle literal constructor model")
959-
val clone = cloneType
959+
val clone: this.type = cloneType
960960
val cloneFields = getRecursiveFields(clone, "_").toMap
961961

962962
// Create the Bundle literal binding from litargs of arguments

core/src/main/scala/chisel3/ChiselEnumImpl.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ private[chisel3] trait ChiselEnumImpl { self: ChiselEnum =>
363363
// This is an enum type that can be connected directly to UInts. It is used as a "glue" to cast non-literal UInts
364364
// to enums.
365365
private[chisel3] class UnsafeEnum(override val width: Width) extends EnumType(UnsafeEnum, selfAnnotating = false) {
366-
367-
override def _cloneType: Data = new UnsafeEnum(width)
366+
override def cloneType: this.type = new UnsafeEnum(width).asInstanceOf[this.type]
368367
}
369368
private object UnsafeEnum extends ChiselEnum
370369

core/src/main/scala/chisel3/DataImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ private[chisel3] trait DataImpl extends HasId with NamedComponent { self: Data =
796796
* Directionality data and probe information is still preserved.
797797
*/
798798
private[chisel3] def cloneTypeFull: this.type = {
799-
val clone = this.cloneType // get a fresh object, without bindings
799+
val clone: this.type = this.cloneType // get a fresh object, without bindings
800800
// Only the top-level direction needs to be fixed up, cloneType should do the rest
801801
clone.specifiedDirection = specifiedDirection
802802
probe.setProbeModifier(clone, probeInfo)

core/src/main/scala/chisel3/properties/Property.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,18 @@ sealed trait Property[T] extends Element { self =>
277277

278278
/** Clone type by simply constructing a new Property[T].
279279
*/
280-
override def _cloneType: Data = new Property[T] {
280+
override def cloneType: this.type = new Property[T] {
281281
val tpe = self.tpe
282+
}.asInstanceOf[this.type]
283+
284+
/** Clone type with extra information preserved.
285+
*
286+
* The only extra information present on a Property type is directionality.
287+
*/
288+
private[chisel3] override def cloneTypeFull: this.type = {
289+
val clone: this.type = this.cloneType
290+
clone.specifiedDirection = specifiedDirection
291+
clone
282292
}
283293

284294
/** Get the IR PropertyType for this Property.

0 commit comments

Comments
 (0)