我写了一些代码
type internal IMyInterface =
abstract member Method1 : unit -> unit
type Class1() =
member this.Y() =
(this :> IMyInterface).Method1()
interface IMyInterface with
member this.Method1() = ()
请注意,公共类型Class1实现了一个内部接口IMyInterface,它编译得很好 . 在生成的MSIL中,“Method1”显示为私有 . 这类似于C#中的显式接口 .
但是,当我将代码更改为
type internal Foo() =
member x.Value = "Foo"
type internal IMyInterface =
abstract member Method1 : Foo -> unit
type Class1() =
member this.Y() =
let v = Foo()
(this :> IMyInterface).Method1(v)
interface IMyInterface with
member this.Method1(v : Foo) = ()
这种类型的接口方法“Method1”采用内部类型“Foo”作为参数 . 这次,它不会编译错误
The type 'Foo' is less accessible than the value, member or type 'override Class1.Method1 : v:Foo -> unit' it is used in
我无法解密此错误消息并找到它的修复程序 . 在C#中,我可以编写以下编译好的代码
internal class Foo
{
string Value { get; set; }
}
internal interface IMyInterface
{
void Method1(Foo v);
}
public class Class1 : IMyInterface
{
public void Y()
{
var v = new Foo();
(this as IMyInterface).Method1(v);
}
void IMyInterface.Method1(Foo v)
{
throw new NotImplementedException();
}
}
有关F#编译器错误以及如何解决它的任何想法?
BTW:这可能不是使用界面的正确方式/模式,我只是对语言语法感到好奇
1 回答
正如Patrick的评论所指出的那样,这个问题被记录为Visual F#的a bug . 目前它已包含在F#4.0 Update 3里程碑中 .