@@ -2471,7 +2471,7 @@ braceFieldDeclList:
2471
2471
{ [] }
2472
2472
2473
2473
| LBRACE rbrace
2474
- { errorR (Error(FSComp.SR.parsExpectingField (), rhs parseState 2))
2474
+ { errorR (Error(FSComp.SR.parsExpectingRecordField (), rhs parseState 2))
2475
2475
[] }
2476
2476
2477
2477
anonRecdType:
@@ -2711,17 +2711,26 @@ attrUnionCaseDecl:
2711
2711
{ fun (xmlDoc, mBar) -> mkSynUnionCase $1 $2 (SynIdent(mkSynId mBar.EndRange "", None)) (SynUnionCaseKind.Fields []) mBar (xmlDoc, mBar) |> Choice2Of2 }
2712
2712
2713
2713
| opt_attributes opt_access unionCaseName OF unionCaseRepr
2714
- { mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.Fields $5) (rhs2 parseState 1 5) >> Choice2Of2 }
2714
+ { let mId = rhs parseState 3
2715
+ let fields, mFields = $5
2716
+ let mWhole = unionRanges mId mFields
2717
+ mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.Fields fields) mWhole >> Choice2Of2 }
2715
2718
2716
2719
| opt_attributes opt_access unionCaseName unionCaseRepr
2717
2720
{ errorR (Error(FSComp.SR.parsMissingKeyword("of"), rhs2 parseState 3 4))
2718
- mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.Fields $4) (rhs2 parseState 1 4) >> Choice2Of2 }
2721
+ let mAttributes = rhs parseState 1
2722
+ let fields, mFields = $4
2723
+ let mWhole = unionRanges mAttributes mFields
2724
+ mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.Fields fields) mWhole >> Choice2Of2 }
2719
2725
2720
2726
| opt_attributes opt_access OF unionCaseRepr
2721
- { let mOf = rhs parseState 3
2727
+ { let mAttributes = rhs parseState 1
2728
+ let mOf = rhs parseState 3
2722
2729
let mId = mOf.StartRange
2730
+ let fields, mFields = $4
2731
+ let mWhole = unionRanges mAttributes mFields
2723
2732
errorR (Error(FSComp.SR.parsMissingUnionCaseName(), mOf))
2724
- mkSynUnionCase $1 $2 (SynIdent(mkSynId mId "", None)) (SynUnionCaseKind.Fields $4) (rhs2 parseState 1 4) >> Choice2Of2 }
2733
+ mkSynUnionCase $1 $2 (SynIdent(mkSynId mId "", None)) (SynUnionCaseKind.Fields fields) mWhole >> Choice2Of2 }
2725
2734
2726
2735
| opt_attributes opt_access OF recover
2727
2736
{ let mOf = rhs parseState 3
@@ -2733,13 +2742,18 @@ attrUnionCaseDecl:
2733
2742
{ mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.Fields []) (rhs2 parseState 1 4) >> Choice2Of2 }
2734
2743
2735
2744
| opt_attributes opt_access unionCaseName COLON topType
2736
- { if parseState.LexBuffer.ReportLibraryOnlyFeatures then libraryOnlyWarning(lhs parseState)
2737
- mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.FullType $5) (rhs2 parseState 1 5) >> Choice2Of2 }
2745
+ { let mAttributes = rhs parseState 1
2746
+ let fullType, _ = $5
2747
+ let mWhole = unionRanges mAttributes fullType.Range
2748
+ if parseState.LexBuffer.ReportLibraryOnlyFeatures then libraryOnlyWarning(lhs parseState)
2749
+ mkSynUnionCase $1 $2 $3 (SynUnionCaseKind.FullType $5) mWhole >> Choice2Of2 }
2738
2750
2739
2751
| opt_attributes opt_access unionCaseName EQUALS atomicExpr
2740
2752
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsEnumFieldsCannotHaveVisibilityDeclarations(), rhs parseState 2))
2741
2753
let mEquals = rhs parseState 4
2742
- let mDecl = rhs2 parseState 1 5
2754
+ let mAttributes = rhs parseState 1
2755
+ let expr, _ = $5
2756
+ let mDecl = unionRanges mAttributes expr.Range
2743
2757
(fun (xmlDoc, mBar) ->
2744
2758
let trivia: SynEnumCaseTrivia = { BarRange = Some mBar; EqualsRange = mEquals }
2745
2759
let mDecl = unionRangeWithXmlDoc xmlDoc mDecl
@@ -2797,16 +2811,20 @@ firstUnionCaseDeclOfMany:
2797
2811
2798
2812
firstUnionCaseDecl:
2799
2813
| ident OF unionCaseRepr
2800
- { let trivia: SynUnionCaseTrivia = { BarRange = None }
2814
+ { let fields, mFields = $3
2815
+ let trivia: SynUnionCaseTrivia = { BarRange = None }
2801
2816
let xmlDoc = grabXmlDoc (parseState, [], 1)
2802
- let mDecl = rhs2 parseState 1 3 |> unionRangeWithXmlDoc xmlDoc
2803
- Choice2Of2(SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields $3, xmlDoc, None, mDecl, trivia)) }
2817
+ let mId = rhs parseState 1
2818
+ let mDecl = unionRanges mId mFields |> unionRangeWithXmlDoc xmlDoc
2819
+ Choice2Of2(SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields fields, xmlDoc, None, mDecl, trivia)) }
2804
2820
2805
- | unionCaseName COLON topType
2821
+ | unionCaseName COLON topType
2806
2822
{ if parseState.LexBuffer.ReportLibraryOnlyFeatures then libraryOnlyWarning(lhs parseState)
2807
2823
let trivia: SynUnionCaseTrivia = { BarRange = None }
2808
2824
let xmlDoc = grabXmlDoc (parseState, [], 1)
2809
- let mDecl = rhs2 parseState 1 3 |> unionRangeWithXmlDoc xmlDoc
2825
+ let mId = rhs parseState 1
2826
+ let fullType, _ = $3
2827
+ let mDecl = unionRanges mId fullType.Range |> unionRangeWithXmlDoc xmlDoc
2810
2828
Choice2Of2(SynUnionCase([], $1, SynUnionCaseKind.FullType $3, xmlDoc, None, mDecl, trivia)) }
2811
2829
2812
2830
| ident OF recover
@@ -2818,18 +2836,21 @@ firstUnionCaseDecl:
2818
2836
| OF unionCaseRepr
2819
2837
{ let mOf = rhs parseState 1
2820
2838
let mId = mOf.StartRange
2839
+ let fields, mFields = $2
2821
2840
errorR (Error(FSComp.SR.parsMissingUnionCaseName(), mOf))
2822
2841
let id = SynIdent(mkSynId mId "", None)
2823
2842
let trivia: SynUnionCaseTrivia = { BarRange = None }
2824
2843
let xmlDoc = grabXmlDoc (parseState, [], 1)
2825
- let mDecl = rhs2 parseState 1 2 |> unionRangeWithXmlDoc xmlDoc
2826
- Choice2Of2(SynUnionCase([], id, SynUnionCaseKind.Fields $2 , xmlDoc, None, mDecl, trivia)) }
2844
+ let mDecl = unionRanges mOf mFields |> unionRangeWithXmlDoc xmlDoc
2845
+ Choice2Of2(SynUnionCase([], id, SynUnionCaseKind.Fields fields , xmlDoc, None, mDecl, trivia)) }
2827
2846
2828
2847
| ident EQUALS atomicExpr opt_OBLOCKSEP
2829
- { let mEquals = rhs parseState 2
2848
+ { let mId = rhs parseState 1
2849
+ let mEquals = rhs parseState 2
2830
2850
let trivia: SynEnumCaseTrivia = { BarRange = None; EqualsRange = mEquals }
2831
2851
let xmlDoc = grabXmlDoc (parseState, [], 1)
2832
- let mDecl = rhs2 parseState 1 3 |> unionRangeWithXmlDoc xmlDoc
2852
+ let expr, _ = $3
2853
+ let mDecl = unionRanges mId expr.Range |> unionRangeWithXmlDoc xmlDoc
2833
2854
Choice1Of2(SynEnumCase([], SynIdent($1, None), fst $3, xmlDoc, mDecl, trivia)) }
2834
2855
2835
2856
| ident EQUALS recover opt_OBLOCKSEP
@@ -2843,10 +2864,26 @@ firstUnionCaseDecl:
2843
2864
2844
2865
unionCaseReprElements:
2845
2866
| unionCaseReprElement STAR unionCaseReprElements
2846
- { $1 :: $3 }
2867
+ { let mField = rhs parseState 1
2868
+ let fields, mFields = $3
2869
+ $1 :: fields, unionRanges mField mFields }
2870
+
2871
+ | unionCaseReprElement STAR recover
2872
+ { let mStar = rhs parseState 2
2873
+ let ty = SynType.FromParseError mStar.EndRange
2874
+ let field = mkSynAnonField (ty, PreXmlDoc.Empty)
2875
+ [$1; field], rhs2 parseState 1 2 }
2876
+
2877
+ | STAR unionCaseReprElements
2878
+ { let mStar = rhs parseState 1
2879
+ errorR (Error(FSComp.SR.parsExpectingUnionCaseField (), rhs parseState 1))
2880
+ let fields, mFields = $2
2881
+ let ty = SynType.FromParseError mStar.StartRange
2882
+ let field = mkSynAnonField (ty, PreXmlDoc.Empty)
2883
+ field :: fields, unionRanges mStar mFields }
2847
2884
2848
2885
| unionCaseReprElement %prec prec_toptuptyptail_prefix
2849
- { [$1] }
2886
+ { [$1], rhs parseState 1 }
2850
2887
2851
2888
unionCaseReprElement:
2852
2889
| ident COLON appTypeNullableInParens
@@ -2872,7 +2909,7 @@ unionCaseReprElement:
2872
2909
unionCaseRepr:
2873
2910
| braceFieldDeclList
2874
2911
{ errorR(Deprecated(FSComp.SR.parsConsiderUsingSeparateRecordType(), lhs parseState))
2875
- $1 }
2912
+ $1, rhs parseState 1 }
2876
2913
2877
2914
| unionCaseReprElements
2878
2915
{ $1 }
@@ -2948,7 +2985,8 @@ exconIntro:
2948
2985
{ SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields [], PreXmlDoc.Empty, None, lhs parseState, { BarRange = None }) }
2949
2986
2950
2987
| ident OF unionCaseRepr
2951
- { SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields $3, PreXmlDoc.Empty, None, lhs parseState, { BarRange = None }) }
2988
+ { let fields, _ = $3
2989
+ SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields fields, PreXmlDoc.Empty, None, lhs parseState, { BarRange = None }) }
2952
2990
2953
2991
| ident OF recover
2954
2992
{ SynUnionCase([], SynIdent($1, None), SynUnionCaseKind.Fields [], PreXmlDoc.Empty, None, lhs parseState, { BarRange = None }) }
0 commit comments