Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The spec requires that both a setter and getter are defined to be able to use the syntactic sugar for calling the setter:</p> <blockquote> <p>The interpretation of an assignment to a simple variable x = e depends on the definition of x. If x denotes a mutable variable, then the assignment changes the current value of x to be the result of evaluating the expression e. The type of e is expected to conform to the type of x. <strong>If x is a parameterless function defined in some template, and the same template contains a setter function x_= as member, then the assignment x = e is interpreted as the invocation x_=(e ) of that setter function.</strong> Analogously, an assignment f .x = e to a parameterless function x is interpreted as the invocation f .x_=(e ). An assignment f (args) = e with a function application to the left of the ‘=’ operator is interpreted as f .update(args, e ), i.e. the invocation of an update function defined by f .</p> </blockquote> <p>Furthermore, the getter must be visible in order to use the setter. I'm not sure if this is specified</p> <h2>Getter not visible #1</h2> <pre><code>// error: method x cannot be accessed in x.Test object x { class Test { private[this] var x0: Int = 0 private[Test] def x = x0 def x_=(a: Int) = x0 = a } val t = new Test t.x = 1 } </code></pre> <h2>Getter not visible #2</h2> <pre><code>//&lt;console&gt;:11: error: type mismatch; found : x.Test required: ?{val x: ?} object x { class Test { private[this] var x0: Int = 0 private[this] def x = x0 def x_=(a: Int) = x0 = a } val t = new Test t.x = 1 } </code></pre> <h2>Getter visible</h2> <pre><code>object x { class Test { private[this] var x0: Int = 0 private[x] def x = x0 def x_=(a: Int) = x0 = a } val t = new Test t.x = 1 } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload