title: When does a += b become a = a + b in Scala?
body: <p>Scala only <em>sometimes</em> desugars</p>
  
  <pre><code>a += b
  </code></pre>
  
  <p>to</p>
  
  <pre><code>a = a + b
  </code></pre>
  
  <p>but not always. For example, some mutable collections define a <code>+=</code> method, where instead it becomes</p>
  
  <pre><code>a.+=(b)
  </code></pre>
  
  <p>Is this behaviour</p>
  
  <ol>
  <li>entirely determined by whether there is a suitable <code>+=</code> method on <code>a</code>? (incl. are there any other examples of this behaviour?)</li>
  <li>independent of whether the objects are val or var?</li>
  </ol>
  
  <p><strong>Relevant example</strong></p>
  
  <p>Adapted from <em>Programming in Scala</em>, in</p>
  
  <pre><code>var s = Set("a", "b")
  s += "c"
  </code></pre>
  
  <blockquote>
    <p>In this case, the second line of code <code>s += "c"</code> is essentially shorthand for:</p>
  </blockquote>
  
  <pre><code>s = s + "c"
  </code></pre>