Scala - Accessible member up to directly inherited class

46 Views Asked by At

Using cake pattern we can set a member only accessible to directly inherited trait

trait A { val a = 1 }
trait B { this: A => val b = a + 1 } // can access a 
trait C { this: B => val c = a + 1 } // will throw error because C cannot access a

I want to apply this member access logic using access modifier rather than self annotation

For example,

trait A { protected[B] val a = 1 } 
trait B extends A { val b = a + 1 } 
trait C extends B { val c = a + 1 } // I want this to throw an error 

Any solution?

0

There are 0 best solutions below