At compile time I want to verify that a class parameter is NOT an instance of a particular trait T. I know how to do it at runtime using require
or a case match
but wondering how this might be done at compile to prevent users from providing certain type of object mixins.
I've looked into scala macros/reflection but not able to wrap my head around that completely.
trait A
trait B
trait T
abstract class C extends A with B
case class P(c: C){
require(!c.isInstanceOf[T]) // how to do this at compile time ?
}
// usage as below
object c1 extends C
object c2 extends C
object c3 extends C
object c4 extends C with T
val l = List(c1, c2, c3, c4).map(k => P(k)) // should fail at compile time