Is there a way to define a collection of alternatives of a common type:
trait Mutability
trait Mutable extends Mutability
trait Immutable extends Mutability
and have the compiler preclude something like:
object Hat extends Mutable with Immutable
I believe I can force some compiler error by having a common, conflicting member but the error message is a bit oblique:
trait Mutability
trait Mutable extends Mutability { protected val conflict = true }
trait Immutable extends Mutability { protected val conflict = true }
object Hat extends Mutable with Immutable
<console>:10: error: object Hat inherits conflicting members:
value conflict in class Immutable$class of type Boolean and
value conflict in class Mutable$class of type Boolean
(Note: this can be resolved by declaring an override in object Hat.)
object Hat extends Immutable with Mutable
Is there a more direct way to express this constraint and not permit someone to work around it by taking the hint offered by the compiler (override 'conflict' in Hat)?
Thanks for any insights
I think this might work
This (ab?)uses the fact that you can't extend the same trait twice with different parameterization
However..