Skip to content

Commit ec1f2e2

Browse files
authored
Anon struct opening token (#14723)
* Add trivia for SynExpr.AnonRecd.
1 parent 1e65a08 commit ec1f2e2

23 files changed

+208
-26
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5520,7 +5520,7 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE
55205520
TcNonControlFlowExpr env <| fun env ->
55215521
TcExprTuple cenv overallTy env tpenv (isExplicitStruct, args, m)
55225522

5523-
| SynExpr.AnonRecd (isStruct, withExprOpt, unsortedFieldExprs, mWholeExpr) ->
5523+
| SynExpr.AnonRecd (isStruct, withExprOpt, unsortedFieldExprs, mWholeExpr, _) ->
55245524
TcNonControlFlowExpr env <| fun env ->
55255525
TcPossiblyPropagatingExprLeafThenConvert (fun ty -> isAnonRecdTy g ty || isTyparTy g ty) cenv overallTy env mWholeExpr (fun overallTy ->
55265526
TcAnonRecdExpr cenv overallTy env tpenv (isStruct, withExprOpt, unsortedFieldExprs, mWholeExpr)

src/Compiler/Service/FSharpParseFileResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
715715

716716
yield! walkExprs (fs |> List.choose (fun (SynExprRecordField (expr = e)) -> e))
717717

718-
| SynExpr.AnonRecd (_isStruct, copyExprOpt, fs, _) ->
718+
| SynExpr.AnonRecd (copyInfo = copyExprOpt; recordFields = fs) ->
719719
match copyExprOpt with
720720
| Some (e, _) -> yield! walkExpr true e
721721
| None -> ()

src/Compiler/Service/ServiceParseTreeWalk.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ module SyntaxTraversal =
351351
| SynExpr.ArrayOrList (_, synExprList, _range) ->
352352
synExprList |> List.map (fun x -> dive x x.Range traverseSynExpr) |> pick expr
353353

354-
| SynExpr.AnonRecd (_isStruct, copyOpt, synExprList, _range) ->
354+
| SynExpr.AnonRecd (copyInfo = copyOpt; recordFields = synExprList) ->
355355
[
356356
match copyOpt with
357357
| Some (expr, (withRange, _)) ->

src/Compiler/SyntaxTree/SyntaxTree.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ type SynExpr =
483483
isStruct: bool *
484484
copyInfo: (SynExpr * BlockSeparator) option *
485485
recordFields: (Ident * range option * SynExpr) list *
486-
range: range
486+
range: range *
487+
trivia: SynExprAnonRecdTrivia
487488

488489
| ArrayOrList of isArray: bool * exprs: SynExpr list * range: range
489490

src/Compiler/SyntaxTree/SyntaxTree.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ type SynExpr =
555555
isStruct: bool *
556556
copyInfo: (SynExpr * BlockSeparator) option *
557557
recordFields: (Ident * range option * SynExpr) list *
558-
range: range
558+
range: range *
559+
trivia: SynExprAnonRecdTrivia
559560

560561
/// F# syntax: [ e1; ...; en ], [| e1; ...; en |]
561562
| ArrayOrList of isArray: bool * exprs: SynExpr list * range: range

src/Compiler/SyntaxTree/SyntaxTreeOps.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ let rec synExprContainsError inpExpr =
841841
| SynExpr.ArrayOrList (_, es, _)
842842
| SynExpr.Tuple (_, es, _, _) -> walkExprs es
843843

844-
| SynExpr.AnonRecd (_, origExpr, flds, _) ->
844+
| SynExpr.AnonRecd (copyInfo = origExpr; recordFields = flds) ->
845845
(match origExpr with
846846
| Some (e, _) -> walkExpr e
847847
| None -> false)

src/Compiler/SyntaxTree/SyntaxTrivia.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ type SynExprMatchBangTrivia =
100100
WithKeyword: range
101101
}
102102

103+
[<NoEquality; NoComparison>]
104+
type SynExprAnonRecdTrivia = { OpeningBraceRange: range }
105+
103106
[<NoEquality; NoComparison>]
104107
type SynMatchClauseTrivia =
105108
{

src/Compiler/SyntaxTree/SyntaxTrivia.fsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ type SynExprMatchBangTrivia =
159159
WithKeyword: range
160160
}
161161

162+
/// Represents additional information for SynExpr.AnonRecd
163+
[<NoEquality; NoComparison>]
164+
type SynExprAnonRecdTrivia =
165+
{
166+
/// The syntax range of the `{|` token.
167+
OpeningBraceRange: range
168+
}
169+
162170
/// Represents additional information for SynMatchClause
163171
[<NoEquality; NoComparison>]
164172
type SynMatchClauseTrivia =

src/Compiler/pars.fsy

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4917,11 +4917,12 @@ braceBarExprCore:
49174917
flds |> List.choose (function
49184918
| SynExprRecordField((SynLongIdent([id], _, _), _), mEquals, Some e, _) -> Some (id, mEquals, e)
49194919
| SynExprRecordField((SynLongIdent([id], _, _), _), mEquals, None, _) -> Some (id, mEquals, arbExpr("anonField", id.idRange))
4920-
| _ -> reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsInvalidAnonRecdType()); None)
4921-
let m = rhs2 parseState 1 3
4920+
| _ -> reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsInvalidAnonRecdType()); None)
4921+
let mLeftBrace = rhs parseState 1
4922+
let mRightBrace = rhs parseState 3
49224923
(fun (mStruct: range option) ->
4923-
let m = match mStruct with | None -> m | Some mStruct -> unionRanges mStruct m
4924-
SynExpr.AnonRecd (mStruct.IsSome, orig, flds, m)) }
4924+
let m = match mStruct with | None -> unionRanges mLeftBrace mRightBrace | Some mStruct -> unionRanges mStruct mRightBrace
4925+
SynExpr.AnonRecd (mStruct.IsSome, orig, flds, m, { OpeningBraceRange = mLeftBrace })) }
49254926

49264927
| LBRACE_BAR recdExprCore recover
49274928
{ reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnmatchedBraceBar())
@@ -4931,30 +4932,33 @@ braceBarExprCore:
49314932
| SynExprRecordField((SynLongIdent([id], _, _), _), mEquals, Some e, _) -> Some (id, mEquals, e)
49324933
| SynExprRecordField((SynLongIdent([id], _, _), _), mEquals, None, _) -> Some (id, mEquals, arbExpr("anonField", id.idRange))
49334934
| _ -> reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsInvalidAnonRecdType()); None)
4934-
let m = rhs2 parseState 1 2
4935+
let mLeftBrace = rhs parseState 1
4936+
let mExpr = rhs parseState 2
49354937
(fun (mStruct: range option) ->
4936-
let m = match mStruct with | None -> m | Some mStruct -> unionRanges mStruct m
4937-
SynExpr.AnonRecd (mStruct.IsSome, orig, flds, m)) }
4938+
let m = match mStruct with | None -> unionRanges mLeftBrace mExpr | Some mStruct -> unionRanges mStruct mExpr
4939+
SynExpr.AnonRecd (mStruct.IsSome, orig, flds, m, { OpeningBraceRange = mLeftBrace })) }
49384940

49394941
| LBRACE_BAR error bar_rbrace
49404942
{ // silent recovery
4941-
let m = rhs2 parseState 1 3
4943+
let mLeftBrace = rhs parseState 1
4944+
let mRightBrace = rhs parseState 3
49424945
(fun (mStruct: range option) ->
4943-
let m = match mStruct with | None -> m | Some mStruct -> unionRanges mStruct m
4946+
let m = match mStruct with | None -> unionRanges mLeftBrace mRightBrace | Some mStruct -> unionRanges mStruct mRightBrace
49444947
arbExpr("braceBarExpr", m)) }
49454948

49464949
| LBRACE_BAR recover
49474950
{ reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnmatchedBraceBar())
4948-
let m = rhs2 parseState 1 1
4951+
let mLeftBrace = rhs parseState 1
49494952
(fun (mStruct: range option) ->
4950-
let m = match mStruct with | None -> m | Some mStruct -> unionRanges mStruct m
4951-
SynExpr.AnonRecd (mStruct.IsSome, None, [], m)) }
4953+
let m = match mStruct with | None -> mLeftBrace | Some mStruct -> unionRanges mStruct mLeftBrace
4954+
SynExpr.AnonRecd (mStruct.IsSome, None, [], m, { OpeningBraceRange = mLeftBrace })) }
49524955

49534956
| LBRACE_BAR bar_rbrace
4954-
{ let m = rhs2 parseState 1 2
4957+
{ let mLeftBrace = rhs parseState 1
4958+
let mRightBrace = rhs parseState 2
49554959
(fun (mStruct: range option) ->
4956-
let m = match mStruct with | None -> m | Some mStruct -> unionRanges mStruct m
4957-
SynExpr.AnonRecd (mStruct.IsSome, None, [], m)) }
4960+
let m = match mStruct with | None -> unionRanges mLeftBrace mRightBrace | Some mStruct -> unionRanges mStruct mRightBrace
4961+
SynExpr.AnonRecd (mStruct.IsSome, None, [], m, { OpeningBraceRange = mLeftBrace })) }
49584962

49594963
anonLambdaExpr:
49604964
| FUN atomicPatterns RARROW typedSequentialExprBlock

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6160,6 +6160,8 @@ FSharp.Compiler.Syntax.SynExpr+AddressOf: FSharp.Compiler.Text.Range opRange
61606160
FSharp.Compiler.Syntax.SynExpr+AddressOf: FSharp.Compiler.Text.Range range
61616161
FSharp.Compiler.Syntax.SynExpr+AnonRecd: Boolean get_isStruct()
61626162
FSharp.Compiler.Syntax.SynExpr+AnonRecd: Boolean isStruct
6163+
FSharp.Compiler.Syntax.SynExpr+AnonRecd: FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia get_trivia()
6164+
FSharp.Compiler.Syntax.SynExpr+AnonRecd: FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia trivia
61636165
FSharp.Compiler.Syntax.SynExpr+AnonRecd: FSharp.Compiler.Text.Range get_range()
61646166
FSharp.Compiler.Syntax.SynExpr+AnonRecd: FSharp.Compiler.Text.Range range
61656167
FSharp.Compiler.Syntax.SynExpr+AnonRecd: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[FSharp.Compiler.Syntax.Ident,Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range],FSharp.Compiler.Syntax.SynExpr]] get_recordFields()
@@ -6899,7 +6901,7 @@ FSharp.Compiler.Syntax.SynExpr: Boolean get_IsWhile()
68996901
FSharp.Compiler.Syntax.SynExpr: Boolean get_IsYieldOrReturn()
69006902
FSharp.Compiler.Syntax.SynExpr: Boolean get_IsYieldOrReturnFrom()
69016903
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewAddressOf(Boolean, FSharp.Compiler.Syntax.SynExpr, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
6902-
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewAnonRecd(Boolean, Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[FSharp.Compiler.Syntax.SynExpr,System.Tuple`2[FSharp.Compiler.Text.Range,Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Position]]]], Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[FSharp.Compiler.Syntax.Ident,Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range],FSharp.Compiler.Syntax.SynExpr]], FSharp.Compiler.Text.Range)
6904+
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewAnonRecd(Boolean, Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[FSharp.Compiler.Syntax.SynExpr,System.Tuple`2[FSharp.Compiler.Text.Range,Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Position]]]], Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[FSharp.Compiler.Syntax.Ident,Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range],FSharp.Compiler.Syntax.SynExpr]], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia)
69036905
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewApp(FSharp.Compiler.Syntax.ExprAtomicFlag, Boolean, FSharp.Compiler.Syntax.SynExpr, FSharp.Compiler.Syntax.SynExpr, FSharp.Compiler.Text.Range)
69046906
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewArbitraryAfterError(System.String, FSharp.Compiler.Text.Range)
69056907
FSharp.Compiler.Syntax.SynExpr: FSharp.Compiler.Syntax.SynExpr NewArrayOrList(Boolean, Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynExpr], FSharp.Compiler.Text.Range)
@@ -9327,6 +9329,10 @@ FSharp.Compiler.SyntaxTrivia.SynExprAndBangTrivia: Microsoft.FSharp.Core.FSharpO
93279329
FSharp.Compiler.SyntaxTrivia.SynExprAndBangTrivia: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] get_InKeyword()
93289330
FSharp.Compiler.SyntaxTrivia.SynExprAndBangTrivia: System.String ToString()
93299331
FSharp.Compiler.SyntaxTrivia.SynExprAndBangTrivia: Void .ctor(FSharp.Compiler.Text.Range, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range])
9332+
FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia: FSharp.Compiler.Text.Range OpeningBraceRange
9333+
FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia: FSharp.Compiler.Text.Range get_OpeningBraceRange()
9334+
FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia: System.String ToString()
9335+
FSharp.Compiler.SyntaxTrivia.SynExprAnonRecdTrivia: Void .ctor(FSharp.Compiler.Text.Range)
93309336
FSharp.Compiler.SyntaxTrivia.SynExprIfThenElseTrivia: Boolean IsElif
93319337
FSharp.Compiler.SyntaxTrivia.SynExprIfThenElseTrivia: Boolean get_IsElif()
93329338
FSharp.Compiler.SyntaxTrivia.SynExprIfThenElseTrivia: FSharp.Compiler.Text.Range IfKeyword

0 commit comments

Comments
 (0)