署名ファイル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
で:
署名における型定義および実装されています実装ではフィールドオフセットが存在していたが、署名ではないため互換性がありませんe。構造体型では、型のシグネチャ内のフィールドが明示されていなければなりませんが、フィールドはまだ 'private'または 'internal'とラベル付けされています。
私はそのようなコードを実行すると、私はMethodMissingException
を持っている:
let foo = FooBarSoftware.Foo<int>() // <==
// System.MethodMissingException:
// Method not found: 'Void FooBarSoftware.Foo~1..ctor()'
また、私は他の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