@@ -14,11 +14,6 @@ open FSharp.Compiler.TypedTree
14
14
open FSharp.Compiler .Xml
15
15
open FSharp.Compiler .SyntaxTrivia
16
16
17
- [<RequireQualifiedAccess; NoEquality; NoComparison>]
18
- type SynExprOrSpreadValue =
19
- | SynExpr of SynExpr
20
- | SpreadValue of TType * Expr
21
-
22
17
/// Merges updates to nested record fields on the same level in record copy-and-update.
23
18
///
24
19
/// `TransformAstForNestedUpdates` expands `{ x with A.B = 10; A.C = "" }`
@@ -33,29 +28,29 @@ type SynExprOrSpreadValue =
33
28
/// which we here convert to
34
29
///
35
30
/// { x with A = { x.A with B = 10; C = "" } }
36
- let GroupUpdatesToNestedFields ( fields : (( Ident list * Ident ) * SynExprOrSpreadValue option ) list ) =
31
+ let GroupUpdatesToNestedFields ( fields : ( ExplicitOrSpread < (Ident list * Ident ) * SynExpr option , ( Ident list * Ident ) * 'Spread > ) list ) =
37
32
let rec groupIfNested res xs =
38
33
match xs with
39
34
| [] -> res
40
35
| [ x ] -> x :: res
41
36
| x :: y :: ys ->
42
37
match x, y with
43
- | ( lidwid, Some( SynExprOrSpreadValue. SynExpr( SynExpr .Record( baseInfo, copyInfo, fields1, m) ))),
44
- (_, Some( SynExprOrSpreadValue. SynExpr( SynExpr .Record( recordFields = fields2) ))) ->
38
+ | ExplicitOrSpread.Explicit ( lidwid, Some( SynExpr.Record( baseInfo, copyInfo, fields1, m))),
39
+ ExplicitOrSpread.Explicit (_, Some( SynExpr.Record( recordFields = fields2))) ->
45
40
let reducedRecd =
46
- ( lidwid, Some( SynExprOrSpreadValue. SynExpr( SynExpr .Record( baseInfo, copyInfo, fields1 @ fields2, m) )))
41
+ ExplicitOrSpread.Explicit ( lidwid, Some( SynExpr.Record( baseInfo, copyInfo, fields1 @ fields2, m)))
47
42
48
43
groupIfNested res ( reducedRecd :: ys)
49
- | ( lidwid, Some( SynExprOrSpreadValue. SynExpr( SynExpr .AnonRecd( isStruct, copyInfo, fields1, m, trivia) ))),
50
- (_, Some( SynExprOrSpreadValue. SynExpr( SynExpr .AnonRecd( recordFields = fields2) ))) ->
44
+ | ExplicitOrSpread.Explicit ( lidwid, Some( SynExpr.AnonRecd( isStruct, copyInfo, fields1, m, trivia))),
45
+ ExplicitOrSpread.Explicit (_, Some( SynExpr.AnonRecd( recordFields = fields2))) ->
51
46
let reducedRecd =
52
- ( lidwid, Some( SynExprOrSpreadValue. SynExpr( SynExpr .AnonRecd( isStruct, copyInfo, fields1 @ fields2, m, trivia) )))
47
+ ExplicitOrSpread.Explicit ( lidwid, Some( SynExpr.AnonRecd( isStruct, copyInfo, fields1 @ fields2, m, trivia)))
53
48
54
49
groupIfNested res ( reducedRecd :: ys)
55
50
| _ -> groupIfNested ( x :: res) ( y :: ys)
56
51
57
52
fields
58
- |> List.groupBy ( fun (( _ , field ), _ ) -> field.idText)
53
+ |> List.groupBy ( fun ( ExplicitOrSpread.Explicit (( _ , field ), _ ) | ExplicitOrSpread.Spread (( _ , field ), _ ) ) -> field.idText)
59
54
|> List.collect ( fun ( _ , fields ) ->
60
55
if fields.Length < 2 then
61
56
fields
@@ -156,23 +151,25 @@ let TransformAstForNestedUpdates (cenv: TcFileState) (env: TcEnv) overallTy (lid
156
151
157
152
match access, fields with
158
153
| _, [] -> failwith " unreachable"
159
- | accessIds, [ ( fieldId, _) ] -> ( accessIds, fieldId), Some exprBeingAssigned
154
+ | accessIds, [ ( fieldId, _) ] ->
155
+ match exprBeingAssigned with
156
+ | ExplicitOrSpread.Explicit exprBeingAssigned -> ExplicitOrSpread.Explicit(( accessIds, fieldId), Some exprBeingAssigned)
157
+ | ExplicitOrSpread.Spread exprBeingAssigned -> ExplicitOrSpread.Spread(( accessIds, fieldId), Some exprBeingAssigned)
158
+
160
159
| accessIds, ( outerFieldId, item) :: rest ->
161
160
checkLanguageFeatureAndRecover cenv.g.langVersion LanguageFeature.NestedCopyAndUpdate ( rangeOfLid lid)
162
161
163
162
CallNameResolutionSink cenv.tcSink ( outerFieldId.idRange, env.NameEnv, item, [], ItemOccurrence.Use, env.AccessRights)
164
163
165
164
let outerFieldId = ident ( outerFieldId.idText, outerFieldId.idRange.MakeSynthetic())
166
165
167
- let recdExpr =
168
- match exprBeingAssigned with
169
- | SynExprOrSpreadValue.SynExpr synExpr ->
170
- Some(
171
- SynExprOrSpreadValue.SynExpr( synExprRecd ( recdExprCopyInfo ( fields |> List.map fst) withExpr) outerFieldId rest synExpr)
172
- )
173
- | SynExprOrSpreadValue.SpreadValue _ -> Some exprBeingAssigned
174
-
175
- ( accessIds, outerFieldId), recdExpr
166
+ match exprBeingAssigned with
167
+ | ExplicitOrSpread.Explicit synExpr ->
168
+ ExplicitOrSpread.Explicit(
169
+ ( accessIds, outerFieldId),
170
+ Some( synExprRecd ( recdExprCopyInfo ( fields |> List.map fst) withExpr) outerFieldId rest synExpr)
171
+ )
172
+ | ExplicitOrSpread.Spread exprBeingAssigned -> ExplicitOrSpread.Spread(( accessIds, outerFieldId), Some exprBeingAssigned)
176
173
177
174
/// When the original expression in copy-and-update is more complex than `{ x with ... }`, like `{ f () with ... }`,
178
175
/// we bind it first, so that it's not evaluated multiple times during a nested update
0 commit comments