2011-02-07 8 views
2

署名ファイル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 
+1

[email protected]に報告してみましたか? – kvb

答えて

3

私にバグのようです。以下は正常に動作します。

署名ファイルFoo.fsi

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() = { 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 

テストファイルtest.fs

module test 

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

反射板にも.ctor()がコードから見付かりません。

Missing Default COnstructor

2

あなたは本当にあなたのクラスでGetEnumeratorメソッドを持っていません。あなたはF#でのインターフェイスと継承についての詳細を読んでください:http://msdn.microsoft.com/en-us/library/dd233225.aspx

あなたは.fsiファイルからGetEnumeratorメソッドの行を削除する場合 http://msdn.microsoft.com/en-us/library/dd233207.aspx 、これを

let foo = FooBarSoftware.Foo<int>(1) 
let e = (foo :> IEnumerable<_>).GetEnumerator() 
関連する問題