From 931f67dda19e2c950399ea2f5564d81a03a67a95 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 6 Nov 2020 21:03:54 +0300 Subject: [PATCH 1/6] Keep extern declaration access --- src/fsharp/pars.fsy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/pars.fsy b/src/fsharp/pars.fsy index a00ccc1894..d82b3c3cb1 100644 --- a/src/fsharp/pars.fsy +++ b/src/fsharp/pars.fsy @@ -2643,7 +2643,7 @@ cPrototype: SynExpr.Ident (ident("failwith", rhs parseState 6)), SynExpr.Const (SynConst.String("extern was not given a DllImport attribute", rhs parseState 8), rhs parseState 8), mRhs) - (fun attrs vis -> + (fun attrs _ -> let bindingId = SynPat.LongIdent (LongIdentWithDots([nm], []), None, Some noInferredTypars, SynArgPats.Pats [SynPat.Tuple(false, args, argsm)], vis, nmm) let binding = mkSynBinding (xmlDoc, bindingId) From 3eca1d84fdebbeb76040171bd864092594aa4b8f Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 6 Nov 2020 21:45:08 +0300 Subject: [PATCH 2/6] Add test --- tests/service/Symbols.fs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index d2ca83a99b..d33126c3ad 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -8,9 +8,10 @@ module Tests.Service.Symbols #endif open FSharp.Compiler.Service.Tests.Common +open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.SyntaxTree open FsUnit open NUnit.Framework -open FSharp.Compiler.SourceCodeServices module ActivePatterns = @@ -57,6 +58,24 @@ match "foo" with getCaseUsages partialPatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|String|_|" +module ExternDeclarations = + [] + let ``Access modifier`` () = + let parseResults, checkResults = getParseAndCheckResults "extern int private f()" + + match parseResults.ParseTree with + | Some (ParsedInput.ImplFile (ParsedImplFileInput (modules = [SynModuleOrNamespace (decls = [decl])]))) -> + match decl with + | SynModuleDecl.Let (_, [Binding (accessibility = accessibility)], _) -> + accessibility |> should equal (Some SynAccess.Private) + | _ -> failwith "Couldn't get f" + | _ -> failwith "Couldn't get bindings" + + match findSymbolByName "f" checkResults with + | :? FSharpMemberOrFunctionOrValue as mfv -> mfv.Accessibility.IsPrivate |> should equal true + | _ -> failwith "Couldn't get f" + + module XmlDocSig = [] From f1d507190927ba7e09220f6176772a54b9cbfe25 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 6 Nov 2020 21:51:39 +0300 Subject: [PATCH 3/6] Simplify test --- tests/service/Common.fs | 11 ++++++++--- tests/service/Symbols.fs | 11 ++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/service/Common.fs b/tests/service/Common.fs index 15d1ea4d24..11d36c20ea 100644 --- a/tests/service/Common.fs +++ b/tests/service/Common.fs @@ -228,10 +228,15 @@ let matchBraces (name: string, code: string) = let braces = checker.MatchBraces(filePath, FSharp.Compiler.Text.SourceText.ofString code, options) |> Async.RunSynchronously braces -let parseSourceCodeAndGetModule (source: string) = - match parseSourceCode ("test", source) with - | Some (ParsedInput.ImplFile (ParsedImplFileInput (_, _, _, _, _, [ moduleOrNamespace ], _))) -> moduleOrNamespace + +let getSingleModuleLikeDecl (input: ParsedInput option) = + match input with + | Some (ParsedInput.ImplFile (ParsedImplFileInput (modules = [ decl ]))) -> decl | _ -> failwith "Could not get module decls" + +let parseSourceCodeAndGetModule (source: string) = + parseSourceCode ("test", source) |> getSingleModuleLikeDecl + /// Extract range info let tups (m:Range.range) = (m.StartLine, m.StartColumn), (m.EndLine, m.EndColumn) diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index d33126c3ad..b69a4161b0 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -63,13 +63,10 @@ module ExternDeclarations = let ``Access modifier`` () = let parseResults, checkResults = getParseAndCheckResults "extern int private f()" - match parseResults.ParseTree with - | Some (ParsedInput.ImplFile (ParsedImplFileInput (modules = [SynModuleOrNamespace (decls = [decl])]))) -> - match decl with - | SynModuleDecl.Let (_, [Binding (accessibility = accessibility)], _) -> - accessibility |> should equal (Some SynAccess.Private) - | _ -> failwith "Couldn't get f" - | _ -> failwith "Couldn't get bindings" + match getSingleModuleLikeDecl parseResults.ParseTree with + | SynModuleOrNamespace (decls = [SynModuleDecl.Let (_, [Binding (accessibility = accessibility)], _)]) -> + accessibility |> should equal (Some SynAccess.Private) + | _ -> failwith "Couldn't get f" match findSymbolByName "f" checkResults with | :? FSharpMemberOrFunctionOrValue as mfv -> mfv.Accessibility.IsPrivate |> should equal true From fcfd2245f29772f20ce4a4b2d69fba9934465127 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 6 Nov 2020 23:00:52 +0300 Subject: [PATCH 4/6] Check no modifier, explicit public modifier --- tests/service/Symbols.fs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index b69a4161b0..065511abab 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -61,16 +61,32 @@ match "foo" with module ExternDeclarations = [] let ``Access modifier`` () = - let parseResults, checkResults = getParseAndCheckResults "extern int private f()" - - match getSingleModuleLikeDecl parseResults.ParseTree with - | SynModuleOrNamespace (decls = [SynModuleDecl.Let (_, [Binding (accessibility = accessibility)], _)]) -> - accessibility |> should equal (Some SynAccess.Private) - | _ -> failwith "Couldn't get f" - - match findSymbolByName "f" checkResults with - | :? FSharpMemberOrFunctionOrValue as mfv -> mfv.Accessibility.IsPrivate |> should equal true - | _ -> failwith "Couldn't get f" + let parseResults, checkResults = getParseAndCheckResults """ +extern int a() +extern int public b() +extern int private c() +""" + let (SynModuleOrNamespace (decls = decls)) = getSingleModuleLikeDecl parseResults.ParseTree + + [ None + Some SynAccess.Public + Some SynAccess.Private ] + |> List.zip decls + |> List.iter (fun (actual, (expected)) -> + match actual with + | SynModuleDecl.Let (_, [Binding (accessibility = access)], _) -> access |> should equal expected + | decl -> failwithf "unexpected decl: %O" decl) + + [ "a", (true, false, false, false) + "b", (true, false, false, false) + "c", (false, false, false, true) ] + |> List.iter (fun (name, expectedAccess) -> + match findSymbolByName name checkResults with + | :? FSharpMemberOrFunctionOrValue as mfv -> + let access = mfv.Accessibility + (access.IsPublic, access.IsProtected, access.IsInternal, access.IsPrivate) + |> should equal expectedAccess + | _ -> failwith "Couldn't get f") module XmlDocSig = From 0bad6622af2831311804d6734fb91d7b02d8dfbd Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 6 Nov 2020 23:04:20 +0300 Subject: [PATCH 5/6] Cleanup --- tests/service/Symbols.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index 065511abab..5b4c3e8619 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -72,7 +72,7 @@ extern int private c() Some SynAccess.Public Some SynAccess.Private ] |> List.zip decls - |> List.iter (fun (actual, (expected)) -> + |> List.iter (fun (actual, expected) -> match actual with | SynModuleDecl.Let (_, [Binding (accessibility = access)], _) -> access |> should equal expected | decl -> failwithf "unexpected decl: %O" decl) @@ -80,13 +80,13 @@ extern int private c() [ "a", (true, false, false, false) "b", (true, false, false, false) "c", (false, false, false, true) ] - |> List.iter (fun (name, expectedAccess) -> + |> List.iter (fun (name, expected) -> match findSymbolByName name checkResults with | :? FSharpMemberOrFunctionOrValue as mfv -> let access = mfv.Accessibility (access.IsPublic, access.IsProtected, access.IsInternal, access.IsPrivate) - |> should equal expectedAccess - | _ -> failwith "Couldn't get f") + |> should equal expected + | _ -> failwithf "Couldn't get mfv: %s" name) module XmlDocSig = From 39a7c6f6193380680f684006d7ef1d94e6475e73 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Sat, 7 Nov 2020 00:14:53 +0300 Subject: [PATCH 6/6] Fix test --- tests/fsharp/typeProviders/helloWorld/provided.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fsharp/typeProviders/helloWorld/provided.fs b/tests/fsharp/typeProviders/helloWorld/provided.fs index bcdc86452e..4601e26f89 100644 --- a/tests/fsharp/typeProviders/helloWorld/provided.fs +++ b/tests/fsharp/typeProviders/helloWorld/provided.fs @@ -196,5 +196,5 @@ module TheOuterType = module DllImportSmokeTest = [] - extern System.UInt32 private GetLastError() + extern System.UInt32 GetLastError()