title: how to make scala type volatile on purpose
body: <p>According to <a href="http://www.scala-lang.org/files/archive/spec/2.11/03-types.html#volatile-types">http://www.scala-lang.org/files/archive/spec/2.11/03-types.html#volatile-types</a>, types are volatile when they adhere to specific conditions. Is it possible to make a type volatile (e.g. by an annotation) which is not of that form? What possible alternatives are there?</p>
  
  <p>My use case is the following: I want to write a library, which exposes types <code>A</code> and <code>B</code> with <code>A &lt;: B</code> and <code>B</code> is volatile. Then as a user of this library, I want to be able to overwrite a value of type <code>A</code> with one of type <code>B</code>:</p>
  
  <pre><code>trait TraitB {
    def doSomething: Unit
  }
  
  trait Library {
    type A
    type B &lt;: A with TraitB
  }
  
  object LibraryUser {
    val library: Library = ???
  
    trait T {
      val x: library.A
    }
  
    object U extends T {
      val x: library.B = ???
    }
  }
  </code></pre>
  
  <p>This fails with the error: </p>
  
  <blockquote>
    <p>error: overriding value x in trait T of type LibraryUser.library.A;
    value x has a volatile type; cannot override a member with non-volatile type</p>
  </blockquote>
  
  <p>But when I make <code>A</code> volatile, this succeeds. Currently, I make <code>A</code> volatile by making it a subclass of an abstract type <code>Abstract</code> which will just be <code>Any</code> in the implementation and otherwise not used:</p>
  
  <pre><code>trait TraitB {
    def doSomething: Unit
  }
  
  trait Library2 {
    protected type Abstract
    type A &lt;: Any with Abstract
    type B &lt;: A with TraitB
  }
  
  trait Library2ImplementationHelper {
    this: Library2 =&gt;
    override type Abstract = Any
  }
  
  object Library2User {
    val library: Library2 = ???
  
    trait T {
      val x: library.A
    }
  
    object U extends T {
      val x: library.B = ???
    }
  }
  </code></pre>
  
  <p>This compiles and works fine, but <code>Abstract</code> is a little bit artificial and I wonder if there's an other way.</p>