I am new to scala, i hava some code which i can’t understand.
trait HasExample1TileOuter{ this: BaseSubsystem =>
private val portName = "example-tilelink"
val exampleInstance = LazyModule(new ExampleTileModule)
val managernode = locateTLBusWrapper(FBUS) //helper scala fn in rocket-chip repo
// FBUS is defined as a val in another file in same package (subsystem pkg)
// the call returns a TL node (an outer) that is part of FBUS
managernode.fromPort(Some(portName))() :=* exampleInstance.dmanode0
}
I can’t understand that using this in the trait,it makes me very confused.If anyone can help me, I would be grateful.Thanks!
That said, for questions about using the language, next time please use the Users forum (this is the Contributors forum). Link here https://users.scala-lang.org/
Speaking of self types, that’s one of the remaining features I wanted to redesign for Scala 3, but in the end it stayed because the list of new features was already too long.
Self types are cryptic for someone who does not know them already. So I thought it would be clearer to allow to redefine the type of This like this:
trait HasExample1TileOuter:
type This <: BaseSubsystem
...
This gives you added power since you now have a convenient way to refer to the type of this. The problem is that This as a name would likely conflict with existing usages, so one has to worry about migration. And I have not found another name that would be as natural as This.
is consistent with using aliases like self in this example. Are we going to get rid of the ability to declare aliases altogether? Aliases can be used (and useful) even without the self-type, like
trait HasExample1TileOuter { self =>
...
But maybe it’s not worth having them after all and we should use a workaround like this?
trait HasExample1TileOuter {
private val self = this
...