签名文件Foo.fsi
:这是一个F#编译器错误吗? #3
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>
实现文件Foo.fs
:
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
编译没有问题,但警告FS0314
:
在签署和执行的类型定义不兼容,因为字段偏移量在实现中存在,但不在签名中即结构类型现在必须在类型的签名中显示它们的字段,尽管字段可能仍被标记为“私有”或“内部”。
当我运行这样的代码,我有MethodMissingException
:
let foo = FooBarSoftware.Foo<int>() // <==
// System.MethodMissingException:
// Method not found: 'Void FooBarSoftware.Foo~1..ctor()'
另外,如果我使用其他的构造函数,并调用GetEnumerator()
方法:
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()'.
这是一个编译器缺陷,在获得FS0314
警告后,允许编译接口而无需执行?
Microsoft (R) F# 2.0 build 4.0.30319.1
您是否尝试将其报告给[email protected]? – kvb 2011-02-08 04:44:59