Compiler construction 这是F编译器的错误吗?3.

Compiler construction 这是F编译器的错误吗?3.,compiler-construction,f#,struct,warnings,Compiler Construction,F#,Struct,Warnings,签名文件Foo.fsi: 这编译很好,但带有警告FS0314: 签名和实现中的类型定义不兼容,因为实现中存在字段偏移量,但签名中不存在字段偏移量。结构类型现在必须在类型的签名中显示它们的字段,尽管这些字段仍然可以标记为“private”或“internal” 当我这样运行代码时,我得到了MethodMissingException: 这是一个编译器错误,它允许在收到FS0314警告后编译接口而无需实现吗 在我看来像个虫子。下面的程序运行良好 签名文件Foo.fsi: 测试文件Test.fs:

签名文件Foo.fsi:

这编译很好,但带有警告FS0314:

签名和实现中的类型定义不兼容,因为实现中存在字段偏移量,但签名中不存在字段偏移量。结构类型现在必须在类型的签名中显示它们的字段,尽管这些字段仍然可以标记为“private”或“internal”

当我这样运行代码时,我得到了MethodMissingException:

这是一个编译器错误,它允许在收到FS0314警告后编译接口而无需实现吗


在我看来像个虫子。下面的程序运行良好

签名文件Foo.fsi:

测试文件Test.fs:

Reflector还显示代码中缺少.ctor


您的类中确实没有GetEnumerator。您应该阅读更多关于F中接口和继承的内容: http://msdn.microsoft.com/en-us/library/dd233225.aspx

如果从.fsi文件中删除GetEnumerator行,则应该可以:

let foo = FooBarSoftware.Foo<int>(1)
let e = (foo :> IEnumerable<_>).GetEnumerator()

你有没有试过向我汇报fsbugs@microsoft.com?
namespace FooBarSoftware
open System.Collections
open System.Collections.Generic

[<Struct>]
type Foo<'T> =
     val offset: int
     new (x:'T) = { offset = 1 }

     interface IEnumerable<'T> with
        member this.GetEnumerator() = null :> IEnumerator<'T>
        member this.GetEnumerator() = null :> IEnumerator
let foo = FooBarSoftware.Foo<int>() // <==

// System.MethodMissingException:
// Method not found: 'Void FooBarSoftware.Foo~1..ctor()'
let foo = FooBarSoftware.Foo<int>(1)
let e = foo.GetEnumerator() // <==

// System.MethodMissingException:
// Method not found: 'System.Collections.Generic.IEnumerator`1<!0>
// FooBarSoftware.Foo`1.GetEnumerator()'.
Microsoft (R) F# 2.0 build 4.0.30319.1
namespace FooBarSoftware
open System.Collections.Generic

//[<Struct>]
type Foo<'T> =
     new: unit -> 'T Foo
     new: 'T   -> 'T Foo

     // doesn't exists in implementation!
     //member public GetEnumerator: unit -> IEnumerator<'T>

     interface IEnumerable<'T>
namespace FooBarSoftware
open System.Collections
open System.Collections.Generic

//[<Struct>]
type Foo<'T> =
    val offset: int
    new () = { offset = 1 }
    new (x:'T) = { offset = 1 }

    //member this.GetEnumerator() = null :> IEnumerator<'T>

    interface IEnumerable<'T> with
        member this.GetEnumerator() = null :> IEnumerator<'T>
        member this.GetEnumerator() = null :> IEnumerator
module test

let foo = FooBarSoftware.Foo<int>() 
let bar = FooBarSoftware.Foo<int>(1)
let e = foo :> seq<_>
let foo = FooBarSoftware.Foo<int>(1)
let e = (foo :> IEnumerable<_>).GetEnumerator()