diff --git a/src/fsharp/pars.fsy b/src/fsharp/pars.fsy index a00ccc18949..d82b3c3cb14 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) diff --git a/tests/fsharp/typeProviders/helloWorld/provided.fs b/tests/fsharp/typeProviders/helloWorld/provided.fs index bcdc86452eb..4601e26f89a 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() diff --git a/tests/service/Common.fs b/tests/service/Common.fs index 15d1ea4d24b..11d36c20ea8 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 d2ca83a99be..5b4c3e86198 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,37 @@ match "foo" with getCaseUsages partialPatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|String|_|" +module ExternDeclarations = + [] + let ``Access modifier`` () = + 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, expected) -> + match findSymbolByName name checkResults with + | :? FSharpMemberOrFunctionOrValue as mfv -> + let access = mfv.Accessibility + (access.IsPublic, access.IsProtected, access.IsInternal, access.IsPrivate) + |> should equal expected + | _ -> failwithf "Couldn't get mfv: %s" name) + + module XmlDocSig = []