Skip to content

Commit e4df6a7

Browse files
authored
Syntax tree: fix type is not included in SynModuleSigDecl.Types range, inline tyconSpfns rule (#11579)
* Syntax tree: fix type is not included in range, inline tyconSpfns rule * Fix lost attributes * Update baselines * Update baselines
1 parent 550bf7d commit e4df6a7

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

src/fsharp/pars.fsy

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ let rangeOfLongIdent(lid:LongIdent) =
321321
%type <ParsedScriptInteraction> interaction
322322
%type <Ident> ident
323323
%type <SynType> typ typEOF
324-
%type <SynTypeDefnSig list> tyconSpfns
324+
%type <SynTypeDefnSig list> tyconSpfnList
325325
%type <SynExpr> patternResult
326326
%type <SynExpr> declExpr
327327
%type <SynExpr> minusExpr
@@ -810,18 +810,21 @@ moduleSpfn:
810810
let m = (rhs2 parseState 1 4, $5) ||> unionRangeWithListBy (fun (d: SynModuleSigDecl) -> d.Range)
811811
SynModuleSigDecl.NestedModule(info, isRec, $5, m) }
812812

813-
| opt_attributes opt_declVisibility tyconSpfns
814-
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
815-
let (SynTypeDefnSig(SynComponentInfo(cas, a, cs, b, c, d, d2, d3), e, f, g)), rest =
816-
match $3 with
817-
| [] -> raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedEmptyModuleDefn())
818-
| h :: t -> h, t
819-
let attrs = $1@cas
820-
let mTc = (g, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
821-
let tc = (SynTypeDefnSig(SynComponentInfo(attrs, a, cs, b, c, d, d2, d3), e, f, mTc))
822-
let lastType = List.tryLast rest |> Option.defaultValue tc |> fun t -> t.Range
823-
let m = mkRange lastType.FileName mTc.Start lastType.End
824-
SynModuleSigDecl.Types (tc :: rest, m) }
813+
| opt_attributes opt_declVisibility typeKeyword tyconSpfnList
814+
{ if Option.isSome $2 then
815+
errorR (Error (FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2))
816+
817+
match $4 with
818+
| [] -> raiseParseErrorAt (rhs2 parseState 3 4) (FSComp.SR.parsUnexpectedEmptyModuleDefn ())
819+
| SynTypeDefnSig (SynComponentInfo (cas, a, cs, b, c, d, d2, d3), e, f, g) :: tail ->
820+
let attrs = $1 @ cas
821+
let mTc =
822+
let keywordM = rhs parseState 3
823+
(keywordM, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range) |> unionRanges g
824+
let tc = (SynTypeDefnSig(SynComponentInfo(attrs, a, cs, b, c, d, d2, d3), e, f, mTc))
825+
let m = (mTc, tail) ||> unionRangeWithListBy (fun (a: SynTypeDefnSig) -> a.Range)
826+
827+
SynModuleSigDecl.Types (tc :: tail, m) }
825828

826829
| opt_attributes opt_declVisibility exconSpfn
827830
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
@@ -870,12 +873,6 @@ moduleSpecBlock:
870873
{ $2 }
871874

872875

873-
/* A group of type definitions in a signature */
874-
tyconSpfns:
875-
| typeKeyword tyconSpfnList
876-
{ $2 }
877-
878-
879876
tyconSpfnList:
880877
| tyconSpfn AND tyconSpfnList
881878
{ $1 :: $3 }

tests/service/Symbols.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ type Meh =
638638
match parseResults with
639639
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
640640
SynModuleOrNamespaceSig(decls = [SynModuleSigDecl.Types(range = r)]) ])) ->
641-
assertRange (3, 5) (5,11) r
641+
assertRange (3, 0) (5,11) r
642642
| _ -> Assert.Fail "Could not get valid AST"
643643

644644
[<Test>]
@@ -653,7 +653,7 @@ type MyRecord =
653653
match parseResults with
654654
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
655655
SynModuleOrNamespaceSig(decls = [SynModuleSigDecl.Types(types = [SynTypeDefnSig.SynTypeDefnSig(range = r)])]) ])) ->
656-
assertRange (2, 5) (4, 30) r
656+
assertRange (2, 0) (4, 30) r
657657
| _ -> Assert.Fail "Could not get valid AST"
658658

659659
[<Test>]
@@ -669,7 +669,7 @@ type MyRecord =
669669
match parseResults with
670670
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
671671
SynModuleOrNamespaceSig(decls = [SynModuleSigDecl.Types(types = [SynTypeDefnSig.SynTypeDefnSig(range = r)])]) ])) ->
672-
assertRange (2, 5) (5, 30) r
672+
assertRange (2, 0) (5, 30) r
673673
| _ -> Assert.Fail "Could not get valid AST"
674674

675675
[<Test>]
@@ -683,7 +683,7 @@ type MyFunction =
683683
match parseResults with
684684
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
685685
SynModuleOrNamespaceSig(decls = [SynModuleSigDecl.Types(types = [SynTypeDefnSig.SynTypeDefnSig(range = r)])]) ])) ->
686-
assertRange (2, 5) (3, 29) r
686+
assertRange (2, 0) (3, 29) r
687687
| _ -> Assert.Fail "Could not get valid AST"
688688

689689
[<Test>]
@@ -698,7 +698,7 @@ type SomeCollection with
698698
match parseResults with
699699
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
700700
SynModuleOrNamespaceSig(decls = [SynModuleSigDecl.Types(types = [SynTypeDefnSig.SynTypeDefnSig(range = r)])]) ])) ->
701-
assertRange (2, 5) (4, 37) r
701+
assertRange (2, 0) (4, 37) r
702702
| _ -> Assert.Fail "Could not get valid AST"
703703

704704
[<Test>]
@@ -745,9 +745,9 @@ and [<CustomEquality>] Bang =
745745
SynTypeDefnSig.SynTypeDefnSig(range = r1)
746746
SynTypeDefnSig.SynTypeDefnSig(range = r2)
747747
]) as t]) ])) ->
748-
assertRange (4, 5) (5, 9) r1
748+
assertRange (4, 0) (5, 9) r1
749749
assertRange (7, 4) (12, 42) r2
750-
assertRange (4, 5) (12, 42) t.Range
750+
assertRange (4, 0) (12, 42) t.Range
751751
| _ -> Assert.Fail "Could not get valid AST"
752752

753753
[<Test>]

0 commit comments

Comments
 (0)