title: Adding value to generic collection in class not allowed because of scope
body: <p>I'm having trouble adding elements to an object that keeps a collection of generic-typed values.  I tried a Minimal Working Example that causes the error:</p>
  
  <pre><code>class OneElementQueue {
  
      type eltType;
  
      var elements : [0..0] eltType;
  
      //initializer
      proc init(type eltType) {
          this.eltType = eltType;
      }
  
      proc add(element : eltType) {
          this.elements[0] = element;
      }
  
      proc remove() : eltType {
          return this.elements[0];
      }   
  } //end of OneElementQueue
  
  class Monkey {
  
      var name: string;
      var age: int;
  
      proc init(name : string, age : int) {
          this.name = name;
          this.age = age;
      }
  
  } //end of class Monkey
  
  
  var q = new owned OneElementQueue(Monkey);
  var m = new owned Monkey("Kyle", 6);
  q.add(m);
  </code></pre>
  
  <p>When I try to compile all of this, I get an error:</p>
  
  <pre><code>$ chpl BadQueue.chpl
  BadQueue.chpl:12: In function 'add':
  BadQueue.chpl:13: error: Scoped variable would outlive the value it is set to
  BadQueue.chpl:12: note: consider scope of element
  $
  </code></pre>
  
  <p>What is the correct way to go about adding something to a generic data structure like this?  How am I going about this the wrong way?</p>