代码之家  ›  专栏  ›  技术社区  ›  Franco Tiveron

递归命名空间不能与类型提供程序静态参数一起正常工作

  •  4
  • Franco Tiveron  · 技术社区  · 7 年前

    #5227

    使用下列工具

    Microsoft Visual Studio Community 2017预览版15.8.0预览版2.0 Visual Studio.15.预览版/15.8.0-Pre.2.0+27729.1 Windows 10上的Microsoft.NET Framework 4.7.02558版

    复制步骤

    • 创建库项目
    • 将目标.NET Framework版本更改为4.5.2
    • 将目标F版本更改为4.1(核心4.4.3.0)
    • 从nuget安装sqlprovider包
    • 用以下代码替换library1.fs内容 ;
    namespace Ns1
    #nowarn "40"
    
    open FSharp.Data.Sql
    
    [<AutoOpen>]
    module Definitions =
        let [<Literal>] connString = @"Valid connection string"
        let t1 = T1() //T1 not defined
    
    type T1() = 
        static member f1() = connString
    
    type amplaSQL = SqlDataProvider<ConnectionString = connString>
    

    正如预期的那样,“let t1=t1()”会给出一个错误,即文件后面定义的T1类型。 这是rec命名空间应该允许的

    • 将第一行更改为“namespace rec ns1”

    预期行为

    没有错误

    实际行为

    正如预期的那样,先前的错误消失了,因为现在即使在受影响的线路中也知道T1。但是,在最后一个代码行中出现了一个新的意外错误,抱怨没有定义connstring

    namespace rec Ns1
    #nowarn "40"
    
    open FSharp.Data.Sql
    
    [<AutoOpen>]
    module Definitions =
        let [<Literal>] connString = @"Valid connection string"
        let t1 = T1()
    
    type T1() = 
        static member f1() = connString
    
    type amplaSQL = SqlDataProvider<ConnectionString = connString> //connString not defined
    

    问题 :是否需要此行为(我是否未正确使用rec命名空间?)还是F编译器的问题?

    0 回复  |  直到 7 年前