title: Compiler bug in F# 4?
body: <p>I have some F# 4.0 source that compiles fine in Debug, but not in Release.</p>
  
  <p>There are no conditional defines, no changes in the inferred types, and nothing else I can think of, that can explain this difference to me.</p>
  
  <p>Did I really stumble on a compiler bug?</p>
  
  <p>This is a snippet with the problematic code.</p>
  
  <pre><code>let oldItems = userDisplayItems |&gt; Seq.toList
  for newItem in newItems do
      match List.tryFind (fun (itemOfOld: UserDisplay.UserDisplayItem) -&gt; itemOfOld.Id = newItem.Id) oldItems with
      | Some oldItem -&gt;
  </code></pre>
  
  <p>The error message refers to the last use of "oldItems", before the "with" keyword at the end of the long line. The error message is:</p>
  
  <blockquote>
    <p>Undefined value 'oldItems : UserDisplayItem list'</p>
  </blockquote>
  
  <p>What!? oldItems is in plain sight a few lines above, and this compiles in Debug, so why not in Release? What does that error message actually mean?</p>
  
  <p>UserDisplayItem is a simple class.
  newItems is a ResizeArray of UserDisplayItem</p>
  
  <p>I looked into the build history, and it compiled fine in Release when UserDisplayItem was an F# immutable record, and not a class.</p>
  
  <p>Visual Studio 2015, F# 4.0, Any CPU, Release, .NET 4.5.2 targeted.</p>
  
  <p>UPDATE:</p>
  
  <p>The following is a complete example. You can create an F# console application, and paste this into Program.fs. I expect it will compile in Debug, but not Release.</p>
  
  <pre><code>open System.Collections.ObjectModel
  
  type User = { Id: int }
  
  [&lt;AllowNullLiteral&gt;]
  type UserDisplayItem(id: int) =
      let mutable id = id
      member x.Id with get() = id and set(v) = id &lt;- v
  
  let userDisplayItems = new ObservableCollection&lt;UserDisplayItem&gt;()
  
  let refreshList () =
      let newItems = userDisplayItems
      let oldItems = userDisplayItems |&gt; Seq.toList
      for newItem in newItems do
          match List.tryFind (fun (itemOfOld: UserDisplayItem) -&gt; itemOfOld.Id = newItem.Id) oldItems with
          | Some oldItem -&gt; ()
          | None -&gt; ()
  </code></pre>
  
  <p>UPDATE 2 :</p>
  
  <p>An even shorter sample.</p>
  
  <pre><code>type UserDisplayItem = { Id: int }
  
  let refreshList () =
      let newItems = new ResizeArray&lt;UserDisplayItem&gt;()
      let oldItems = new ResizeArray&lt;UserDisplayItem&gt;() |&gt; Seq.toList
      for newItem in newItems do
          match List.tryFind (fun (itemOfOld: UserDisplayItem) -&gt; itemOfOld.Id = newItem.Id) oldItems with
          | Some oldItem -&gt; ()
          | None -&gt; ()
  </code></pre>