Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,12 +2326,10 @@ module InferredSigPrinting =
let outerPath = mspec.CompilationPath.AccessPath

let denv =
innerPath
|> List.choose (fun (path, kind) ->
match kind with
| ModuleOrNamespaceKind.Namespace false -> None
| _ -> Some path)
|> denv.AddOpenPath
if not (isConcreteNamespace def) then
denv
else
denv.AddOpenPath (List.map fst innerPath)

if mspec.IsImplicitNamespace then
// The current mspec is a namespace that belongs to the `def` child (nested) module(s).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\service\FsUnit.fs">
<Link>FsUnit.fs</Link>
</Compile>
<Compile Include="Conformance\BasicGrammarElements\OperatorNames\OperatorNames.fs" />
<Compile Include="Conformance\BasicGrammarElements\PrecedenceAndOperators\PrecedenceAndOperators.fs" />
<Compile Include="Conformance\BasicTypeAndModuleDefinitions\ExceptionDefinitions\ExceptionDefinitions.fs" />
Expand Down Expand Up @@ -193,6 +196,7 @@
<Compile Include="Globalization\GlobalizationTestCases.fs" />
<Compile Include="OCamlCompat\OCamlCompat.fs" />
<Compile Include="Miscellaneous\ListLiterals.fs" />
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />
</ItemGroup>
<ItemGroup>
<Content Include="resources\**" CopyToOutputDirectory="Never" CopyToPublishDirectory="PreserveNewest" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module FSharp.Compiler.ComponentTests.Signatures.ModuleOrNamespaceTests

open System
open Xunit
open FsUnit
open FSharp.Test.Compiler

let private prependNewline v = String.Concat("\n", v)

let equal x =
let x =
match box x with
| :? String as s -> s.Replace("\r\n", "\n") |> box
| x -> x

equal x

[<Fact>]
let ``Type from shared namespace`` () =
FSharp
"""
namespace Foo.Types

type Area = | Area of string * int

namespace Foo.Other

type Map<'t,'v> =
member this.Calculate : Foo.Types.Area = failwith "todo"
"""
|> printSignatures
|> prependNewline
|> should
equal
"""
namespace Foo.Types

type Area = | Area of string * int
namespace Foo.Other

type Map<'t,'v> =

member Calculate: Foo.Types.Area"""

[<Fact>]
let ``Return type used in own type definition`` () =
FSharp
"""
namespace Hey.There

type Foo =
static member Zero : Foo = failwith "todo"
"""
|> printSignatures
|> prependNewline
|> should
equal
"""
namespace Hey.There

type Foo =

static member Zero: Foo"""

[<Fact>]
let ``Function types`` () =
FSharp
"""
namespace Fantomas.Core

module Context =
type Context = { SourceCode: string }

namespace FSharp.Compiler

module Syntax =

type SynExpr =
| IfThenElse
| While

module Text =
type Range =
struct
val startLine: int
val startColumn: int
val endLine: int
val endColumn: int
end

namespace Fantomas.Core

module internal CodePrinter =

open FSharp.Compiler
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open Fantomas.Core.Context

type ASTContext =
{ Meh: bool }
static member Default = { Meh = false }

let rec genExpr (e: SynExpr) (ctx: Context) = ctx

and genLambdaArrowWithTrivia
(bodyExpr: SynExpr -> Context -> Context)
(body: SynExpr)
(arrowRange: Range option)
: Context -> Context =
id"""
|> printSignatures
|> prependNewline
|> should
equal
"""
namespace Fantomas.Core

module Context =

type Context =
{ SourceCode: string }
namespace FSharp.Compiler

module Syntax =

type SynExpr =
| IfThenElse
| While

module Text =

[<Struct>]
type Range =

val startLine: int

val startColumn: int

val endLine: int

val endColumn: int
namespace Fantomas.Core

module internal CodePrinter =

type ASTContext =
{ Meh: bool }

static member Default: ASTContext

val genExpr: e: FSharp.Compiler.Syntax.SynExpr -> ctx: Context.Context -> Context.Context

val genLambdaArrowWithTrivia: bodyExpr: (FSharp.Compiler.Syntax.SynExpr -> Context.Context -> Context.Context) -> body: FSharp.Compiler.Syntax.SynExpr -> arrowRange: FSharp.Compiler.Text.Range option -> (Context.Context -> Context.Context)"""
13 changes: 12 additions & 1 deletion tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,19 @@ module rec Compiler =

let actual =
text.ToString().Split('\n')
|> Array.map (fun s -> s.TrimEnd(' '))
|> Array.map (fun s -> s.TrimEnd(' ', '\r'))
|> Array.filter (fun s -> s.Length > 0)

if not (actual |> Array.contains expected) then
failwith ($"The following signature:\n%s{expected}\n\nwas not found in:\n" + (actual |> String.concat "\n"))

let printSignatures cUnit =
cUnit
|> typecheckResults
|> signatureText
|> string
|> fun s ->
s.Replace("\r", "").Split('\n')
|> Array.map (fun line -> line.TrimEnd())
|> String.concat "\n"
|> fun tap -> tap