 <blockquote> <p>I am just curious: how is <code>val 2 = 123</code> understood by Scala?</p> </blockquote> <p>You can think of <code>val 2 = 123</code> as:</p> <pre><code>123 match { case 2 =&gt; 2 } </code></pre> <p>The variable name part in Scala isn't always a simple name, it can also be a <strong>pattern</strong>, for example:</p> <pre><code>val (x, y) = (1, 2) </code></pre> <p>Will decompose 1 and 2 to x and y, respectively. In scala, everything which is allowed after a <em>case</em> statement is also allowed after <em>val</em> and is translated to a pattern match. </p> <p><a href="http://www.scala-lang.org/files/archive/spec/2.11/04-basic-declarations-and-definitions.html#value-declarations-and-definitions" rel="nofollow">From the specification</a> (emphasis mine):</p> <blockquote> <p>Value definitions can alternatively have <strong>a pattern</strong> as left-hand side. If <strong>p is some pattern</strong> other than a simple name or a name followed by a colon and a type, then the value definition <code>val p = e</code> is expanded as follows:</p> </blockquote> <p>(Skipping to the relevant example):</p> <blockquote> <p>If p has a unique bound variable x:</p> </blockquote> <pre><code>val x = e match { case p =&gt; x } </code></pre> <p>This is the reason the compiler doesn't emit a compile time error. There is a lengthy discussion of the subject in this <a href="https://groups.google.com/forum/#!topic/scala-user/k57U6jt8Za0" rel="nofollow">google group question</a>.</p>