-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14287 from dotnet/merges/main-to-release/dev17.5
Merge main to release/dev17.5
- Loading branch information
Showing
5 changed files
with
181 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
tests/FSharp.Compiler.ComponentTests/FSharpChecker/SymbolUse.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module FSharp.Compiler.ComponentTests.FSharpChecker.SymbolUse | ||
|
||
open FSharp.Compiler.CodeAnalysis | ||
open Xunit | ||
open FSharp.Test.ProjectGeneration | ||
|
||
|
||
module IsPrivateToFile = | ||
|
||
[<Fact>] | ||
let ``Function definition in signature file`` () = | ||
let project = SyntheticProject.Create( | ||
sourceFile "First" [] |> addSignatureFile, | ||
sourceFile "Second" ["First"]) | ||
|
||
project.Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(5, 6, "let f2 x = x + 1", ["f2"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
Assert.False(symbolUse.IsPrivateToFile)) | ||
} | ||
|
||
[<Fact>] | ||
let ``Function definition, no signature file`` () = | ||
let project = SyntheticProject.Create( | ||
sourceFile "First" [], | ||
sourceFile "Second" ["First"]) | ||
|
||
project.Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(5, 6, "let f2 x = x + 1", ["f2"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
Assert.False(symbolUse.IsPrivateToFile)) | ||
} | ||
|
||
[<Fact>] | ||
let ``Function definition not in signature file`` () = | ||
let projectName = "IsPrivateToFileTest1" | ||
let signature = $""" | ||
module {projectName}.ModuleFirst | ||
type TFirstV_1<'a> = | TFirst of 'a | ||
val f: x: 'a -> TFirstV_1<'a> | ||
// no f2 here | ||
""" | ||
let project = SyntheticProject.Create(projectName, | ||
{ sourceFile "First" [] with SignatureFile = Custom signature }, | ||
sourceFile "Second" ["First"]) | ||
|
||
project.Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(5, 6, "let f2 x = x + 1", ["f2"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
Assert.True(symbolUse.IsPrivateToFile)) | ||
} | ||
|
||
[<Fact>] | ||
let ``Function parameter, no signature file`` () = | ||
SyntheticProject.Create(sourceFile "First" []).Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(5, 8, "let f2 x = x + 1", ["x"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
Assert.True(symbolUse.IsPrivateToFile)) | ||
} | ||
|
||
/// This is a bug: https://github.com/dotnet/fsharp/issues/14277 | ||
[<Fact>] | ||
let ``Function parameter, with signature file`` () = | ||
SyntheticProject.Create(sourceFile "First" [] |> addSignatureFile).Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(5, 8, "let f2 x = x + 1", ["x"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
// This should be false, because it's also in the signature file | ||
Assert.True(symbolUse.IsPrivateToFile)) | ||
} | ||
|
||
[<Fact>] | ||
let ``Private function, with signature file`` () = | ||
SyntheticProject.Create( | ||
{ sourceFile "First" [] with ExtraSource = "let private f3 x = x + 1" } | ||
|> addSignatureFile).Workflow { | ||
checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
let symbolUse = typeCheckResult.GetSymbolUseAtLocation(6, 14, "let private f3 x = x + 1", ["f3"]) |> Option.defaultWith (fun () -> failwith "no symbol use found") | ||
Assert.False(symbolUse.IsPrivateToFile)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters