I would like to do something like this (example is simplified, but contains all the crucial pieces):

class Master
{
  type DataType = Int
  var counter : DataType = 0
}

class Slave(private val master : Master)
{
  val counter = master.counter  // (*)
}

And here (*) I get error:

private value master escapes its defining scope as part of type Slave.this.master.DataType

val counter = master.counter

I understand the error, but I don't understand the reason - the type is part of the class Master, not the object master, so it is important if the class is private, not an object. Well, at least in theory.

It is easy to make a quick workaround:

  val counter : Master#DataType = master.counter  

But I believe this is an explicit version of the exactly same code as before, it "only" takes more typing. Is this a feature then?

QUESTION:

Can a type (here DataType) be dependent of the object, and not the class (i.e. type definition per instance of the class) in Scala?

Edit
Report