safesparrow / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
1 stars 0 forks source link

Couldn't type check Fantomas.Core #7

Closed nojaf closed 1 year ago

nojaf commented 1 year ago

Hello,

I believe you already know about this problem and we've talked about it but I found an example in the wild:

let fantomasCoreFiles =
    let triviaTypes = """
module internal Fantomas.Core.TriviaTypes

open FSharp.Compiler.Syntax
open FSharp.Compiler.Text

type FsAstType =
    /// Root node of the syntax tree
    | ParsedInput_
    | Ident_
    | SynIdent_
    | LongIdent_
    | SynLongIdent_
"""

    let version = """
module internal Fantomas.Core.Version

open System.Reflection

let fantomasVersion =
    lazy
        (let assembly = typeof<TriviaTypes.FsAstType>.Assembly

         assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
         |> Option.ofObj
         |> Option.map (fun a -> a.InformationalVersion)
         |> Option.defaultValue (Assembly.GetExecutingAssembly().GetName().Version.ToString()))
"""

    [
        "TriviaTypes.fs", triviaTypes
        "Version.fs", version
    ]

[<Test>]
let ``Fantomas.Core mismatch`` () =
    let nodes =
        fantomasCoreFiles
        |> List.mapi (fun i (name, code) ->
            {
                Idx = FileIdx.make i
                //Code = code
                AST = parseSourceCode(name, code)
            } : SourceFile)
        |> List.toArray

    let graph = AutomatedDependencyResolving.detectFileDependencies nodes
    do ()
    let getDepsOfFile fileName =
        graph.Graph
        |> Seq.pick (fun (KeyValue(f, deps)) -> if System.IO.Path.GetFileName f.Name = fileName then Some deps.Length else None)

    Assert.AreEqual(0, getDepsOfFile "TriviaTypes.fs")
    Assert.AreEqual(1, getDepsOfFile "Version.fs")

Both files share the internal Fantomas.Core namespace. The link in the second file to the first is not being picked up. typeof<TriviaTypes.FsAstType> should be recognized as Fantomas.Core.TriviaTypes.FsAstType.

safesparrow commented 1 year ago

@nojaf Can you check if this now works? Thanks.

nojaf commented 1 year ago

This is no longer actionable.