From a89b9ff41953a4adb920092f26f4f201f2d73d4b Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Mon, 29 Nov 2021 15:14:43 +0100 Subject: [PATCH] Include range of attributes in SynExceptionDefnRepr, SynExceptionSig & SynModuleSigDecl.Exception. (#12441) --- src/fsharp/pars.fsy | 6 +++-- tests/service/Symbols.fs | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/fsharp/pars.fsy b/src/fsharp/pars.fsy index f9b5444a58d..213c8a5a129 100644 --- a/src/fsharp/pars.fsy +++ b/src/fsharp/pars.fsy @@ -827,8 +827,10 @@ moduleSpfn: { if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2)) let (SynExceptionSig(SynExceptionDefnRepr(cas, a, b, c, d, d2), withKeyword, members, range)) = $3 let xmlDoc = grabXmlDoc(parseState, $1, 1) - let ec = SynExceptionSig(SynExceptionDefnRepr($1@cas, a, b, xmlDoc, d, d2), withKeyword, members, range) - SynModuleSigDecl.Exception(ec, rhs parseState 3) } + let mDefnReprWithAttributes = (d2, $1) ||> unionRangeWithListBy (fun a -> a.Range) + let mWhole = (mDefnReprWithAttributes, members) ||> unionRangeWithListBy (fun (m: SynMemberSig) -> m.Range) + let ec = SynExceptionSig(SynExceptionDefnRepr($1@cas, a, b, xmlDoc, d, mDefnReprWithAttributes), withKeyword, members, mWhole) + SynModuleSigDecl.Exception(ec, mWhole) } | openDecl { SynModuleSigDecl.Open($1, (rhs parseState 1)) } diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index 2c3bf311292..7ee0d0b8b70 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -1413,6 +1413,56 @@ type Foo = assertRange (5, 30) (5, 34) mWithKeyword | _ -> Assert.Fail "Could not get valid AST" + [] + let ``Range of attribute should be included in SynExceptionDefnRepr and SynExceptionSig`` () = + let parseResults = + getParseResultsOfSignatureFile + """ +module internal FSharp.Compiler.ParseHelpers + +/// The error raised by the parse_error_rich function, which is called by the parser engine +[] +exception SyntaxError of obj * range: range + + +""" + + match parseResults with + | ParsedInput.SigFile (ParsedSigFileInput (modules=[ + SynModuleOrNamespaceSig(decls=[ + SynModuleSigDecl.Exception( + SynExceptionSig(exnRepr=SynExceptionDefnRepr(range=mSynExceptionDefnRepr); range=mSynExceptionSig), mException) + ] ) ])) -> + assertRange (5, 0) (6, 43) mSynExceptionDefnRepr + assertRange (5, 0) (6, 43) mSynExceptionSig + assertRange (5, 0) (6, 43) mException + | _ -> Assert.Fail "Could not get valid AST" + + [] + let ``Range of members should be included in SynExceptionSig and SynModuleSigDecl.Exception`` () = + let parseResults = + getParseResultsOfSignatureFile + """ +module internal FSharp.Compiler.ParseHelpers + +exception SyntaxError of obj * range: range with + member Meh : string -> int + +open Foo +""" + + match parseResults with + | ParsedInput.SigFile (ParsedSigFileInput (modules=[ + SynModuleOrNamespaceSig(decls=[ + SynModuleSigDecl.Exception( + SynExceptionSig(exnRepr=SynExceptionDefnRepr(range=mSynExceptionDefnRepr); range=mSynExceptionSig), mException) + SynModuleSigDecl.Open _ + ] ) ])) -> + assertRange (4, 0) (4, 43) mSynExceptionDefnRepr + assertRange (4, 0) (5, 30) mSynExceptionSig + assertRange (4, 0) (5, 30) mException + | _ -> Assert.Fail "Could not get valid AST" + module SynMatchClause = [] let ``Range of single SynMatchClause`` () =