4中的编译器错误

4中的编译器错误

本文介绍了F#4中的编译器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些F#4.0源代码,可以在Debug中很好地进行编译,但在Release中却没有.

I have some F# 4.0 source that compiles fine in Debug, but not in Release.

没有条件定义,没有对推断的类型进行任何更改,而且我想不出什么,可以向我解释这种差异.

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.

我真的偶然发现了编译器错误吗?

Did I really stumble on a compiler bug?

这是有问题的代码段.

let oldItems = userDisplayItems |> Seq.toList
for newItem in newItems do
    match List.tryFind (fun (itemOfOld: UserDisplay.UserDisplayItem) -> itemOfOld.Id = newItem.Id) oldItems with
    | Some oldItem ->

错误消息指的是长行末尾"with"关键字之前的"oldItems"的最后使用.错误消息是:

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:

什么!? oldItems在上面几行很明显,并且可以在Debug中编译,所以为什么不在Release中呢?该错误消息实际上是什么意思?

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?

UserDisplayItem是一个简单的类.newItems是UserDisplayItem的ResizeArray

UserDisplayItem is a simple class.newItems is a ResizeArray of UserDisplayItem

我查看了构建历史记录,当UserDisplayItem是F#不变记录而不是类时,它在Release中可以很好地编译.

I looked into the build history, and it compiled fine in Release when UserDisplayItem was an F# immutable record, and not a class.

Visual Studio 2015,F#4.0,任何CPU,发行版,.NET 4.5.2为目标.

Visual Studio 2015, F# 4.0, Any CPU, Release, .NET 4.5.2 targeted.

更新:

以下是一个完整的示例.您可以创建一个F#控制台应用程序,并将其粘贴到Program.fs中.我希望它可以在Debug中编译,但不能在Release中编译.

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.

open System.Collections.ObjectModel

type User = { Id: int }

[<AllowNullLiteral>]
type UserDisplayItem(id: int) =
    let mutable id = id
    member x.Id with get() = id and set(v) = id <- v

let userDisplayItems = new ObservableCollection<UserDisplayItem>()

let refreshList () =
    let newItems = userDisplayItems
    let oldItems = userDisplayItems |> Seq.toList
    for newItem in newItems do
        match List.tryFind (fun (itemOfOld: UserDisplayItem) -> itemOfOld.Id = newItem.Id) oldItems with
        | Some oldItem -> ()
        | None -> ()

更新2:

更短的样本.

type UserDisplayItem = { Id: int }

let refreshList () =
    let newItems = new ResizeArray<UserDisplayItem>()
    let oldItems = new ResizeArray<UserDisplayItem>() |> Seq.toList
    for newItem in newItems do
        match List.tryFind (fun (itemOfOld: UserDisplayItem) -> itemOfOld.Id = newItem.Id) oldItems with
        | Some oldItem -> ()
        | None -> ()

推荐答案

似乎是编译器错误(可能与 1020 ).
可以与您的代码和F#版本14.0.23413.0一起复制它
现在安装了当前的预览,它是F#版本14.0.23618.0和可以.

Seems to be compiler bug (maybe related to 1020).
Could reproduce it with your code and F# version 14.0.23413.0
Now installed current preview which is F# version 14.0.23618.0 and it works.

这篇关于F#4中的编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:59