title: Invalid use of a type field or array element as a loop counter
body: <p>In the following code, I have tried using a field variable (of class or record) or an array element directly as a loop counter, but this was illegal ("error: invalid index expression"). Is this simply because the loop counter must be a scalar variable?</p>
  
  <pre><code>class Cls {
      var n: int;
  }
  
  proc main()
  {
      var x = new Cls( 100 );
      var k: [1..10] int;
  
      for x.n in 1..3 do      // error: invalid index expression
          writeln( x.n );
  
      for k[1] in 1..3 do     // error: invalid index expression
          writeln( k[1] );
  }
  </code></pre>
  
  <p>On the other hand, if I create a reference to <code>x.n</code>, it compiled successfully but <code>x</code> in the outer scope was not modified. Is this because a new loop variable named <code>n</code> is created in the for-loop? (which I'm afraid is almost the same as my another <a href="https://stackoverflow.com/questions/49948407/whether-loop-variables-are-always-freshly-created">question</a>...)</p>
  
  <pre><code>proc main()
  {
      var x = new Cls( 100 );
      ref n = x.n;
  
      for n in 1..3 do
          writeln( n );
  
      writeln( "x = ", x );   // x = {n = 100}
  }
  </code></pre>
  
  <p>If a loop variable is created independently, I guess something like "var x.n = ..." might happen (internally) if I write <code>for x.n in 1..3</code>, which seems really invalid (because it means that I'm trying to declare a loop variable with a name <code>x.n</code>).</p>