title: Why is my string nil?
body: <p>I made this simple program that reads characters until the enter key is pressed</p>
  
  <pre><code>var data: string
  
  while true:
      var c = readChar(stdin) # read char
  
      case c
      of '\r': # if enter, stop
      break
      else: discard
  
      data.add(c) # add the read character to the string
  
  echo data
  </code></pre>
  
  <p>But when it tries to <code>echo data</code>, it crashes</p>
  
  <pre><code>&gt; ./program
  hello
  Traceback (most recent call last)
  program.nim(11)          program
  SIGSEGV: Illegal storage access. (Attempt to read from nil?)
  </code></pre>
  
  <p>This means <code>data</code> is nil. But every time I press enter a character, it adds the character to <code>data</code>. Something goes wrong, but where?</p>