title: Scala constant expressions and computed string literals
body: <p>I'm running into some trickiness with Java annotations and the stipulation that their arguments must be "constants". 6.24 of the Scala 2.8 Language Specification states that "constant expressions" are any of the following (emphasis mine):</p>
  
  <ul>
  <li>A literal of a value class, such as an integer</li>
  <li><em>A string literal</em></li>
  <li>A class constructed with Predef.classOf (§12.5)</li>
  <li>An element of an enumeration from the underlying platform</li>
  <li>A literal array, of the form Array(c1, ..., cn), where all of the ci’s are themselves
  constant expressions</li>
  <li>An identiﬁer deﬁned by a constant value deﬁnition (§4.1).</li>
  </ul>
  
  <p>Now, a "string literal" seems to be defined in such a way that it's really just one " " or """ """ delimited block of characters, which is pretty clear-cut. My question, then, is why given</p>
  
  <pre><code>object MyObject {
    final val MY_CONSTANT1="foo"
    final val MY_CONSTANT2="bar" + "baz"
    final val MY_CONSTANT3="qux" + "quux" + "frobozz"
  }
  
  // ...
  
  @MyAnnotation( ??? )
  def Foo(): Unit {
  ...
  </code></pre>
  
  <p><code>@MyAnnotation</code> compiles and scaladocs with MY_CONSTANT1 and MY_CONSTANT2, but not MY_CONSTANT3 (I get "annotation argument needs to be a constant"). Why does MY_CONSTANT2 work at all? Is there some unspecified at-most-two-string-literals-can-combine-to-become-a-larger-one rule at work, or am I insane?</p>
  
  <p><em>edit</em> I'm using Scala 2.10, which seems to have fixed some annotation-related compiler errors from earlier Scala versions.</p>