@@ -1918,11 +1918,6 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ExplicitOrSpread<(Ident l
1918
1918
let ad = env.eAccessRights
1919
1919
1920
1920
let allFields = flds |> List.map (fun (ExplicitOrSpread.Explicit ((_, ident), _) | ExplicitOrSpread.Spread ((_, ident), _)) -> ident)
1921
- if allFields.Length > 1 then
1922
- // In the case of nested record fields on the same level in record copy-and-update.
1923
- // We need to reverse the list to get the correct order of fields.
1924
- let idents = if isPartial then allFields |> List.rev else allFields
1925
- CheckRecdExprDuplicateFields idents
1926
1921
1927
1922
let fldResolutions =
1928
1923
flds
@@ -7804,11 +7799,15 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, m
7804
7799
// we assume that parse errors were already reported
7805
7800
raise (ReportedError None)
7806
7801
7807
- let ExplicitOrSpread.Explicit ((_ , fieldId), _) | ExplicitOrSpread.Spread ((_, fieldId), _) as field =
7802
+ let isFromNestedUpdate , fieldId, field =
7808
7803
match withExprOpt, synLongId.LongIdent, exprBeingAssigned with
7809
- | _, [ id ], _ -> ExplicitOrSpread.Explicit (([], id), exprBeingAssigned)
7810
- | Some (origExpr, blockSep), lid, Some exprBeingAssigned -> TransformAstForNestedUpdates cenv env overallTy lid (ExplicitOrSpread.Explicit exprBeingAssigned) (origExpr, blockSep)
7811
- | _ -> ExplicitOrSpread.Explicit (List.frontAndBack synLongId.LongIdent, exprBeingAssigned)
7804
+ | _, [ id ], _ -> false, id, ExplicitOrSpread.Explicit (([], id), exprBeingAssigned)
7805
+ | Some (origExpr, blockSep), lid, Some exprBeingAssigned ->
7806
+ let _, id as longIdent, exprBeingAssigned = TransformAstForNestedUpdates cenv env overallTy lid exprBeingAssigned (origExpr, blockSep)
7807
+ true, id, ExplicitOrSpread.Explicit (longIdent, exprBeingAssigned)
7808
+ | _ ->
7809
+ let _, id as longIdent = List.frontAndBack synLongId.LongIdent
7810
+ false, id, ExplicitOrSpread.Explicit (longIdent, exprBeingAssigned)
7812
7811
7813
7812
let flds =
7814
7813
flds |> Map.change fieldId.idText (function
@@ -7827,7 +7826,8 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, m
7827
7826
//
7828
7827
// Keep both, but error.
7829
7828
| Some (LeftwardExplicit, dupes) ->
7830
- errorR (Duplicate ("field", fieldId.idText, m))
7829
+ if not isFromNestedUpdate then
7830
+ errorR (Error (FSComp.SR.tcMultipleFieldsInRecord fieldId.idText, m))
7831
7831
Some (LeftwardExplicit, (i, field) :: dupes)
7832
7832
7833
7833
// Rightward explicit field shadowing leftward spread field.
@@ -8359,11 +8359,13 @@ and TcCopyAndUpdateAnonRecdExpr cenv (overallTy: TType) env tpenv (isStruct, (or
8359
8359
List.rev spreadSrcs, fieldsInOriginalOrder, tpenv
8360
8360
8361
8361
| SynExprAnonRecordFieldOrSpread.Field (SynExprAnonRecordField (fieldName = synLongIdent; expr = exprBeingAssigned; range = m), _) :: fieldsAndSpreads ->
8362
- let ExplicitOrSpread.Explicit ((_ , fieldId), _) | ExplicitOrSpread.Spread ((_, fieldId), _) as field =
8362
+ let isFromNestedUpdate , fieldId, field =
8363
8363
match synLongIdent.LongIdent with
8364
8364
| [] -> error(Error(FSComp.SR.nrUnexpectedEmptyLongId(), mWholeExpr))
8365
- | [ id ] -> ExplicitOrSpread.Explicit (([], id), Some exprBeingAssigned)
8366
- | lid -> TransformAstForNestedUpdates cenv env origExprTy lid (ExplicitOrSpread.Explicit exprBeingAssigned) (origExpr, blockSeparator)
8365
+ | [ id ] -> false, id, ExplicitOrSpread.Explicit (([], id), Some exprBeingAssigned)
8366
+ | lid ->
8367
+ let _, id as longIdent, exprBeingAssigned = TransformAstForNestedUpdates cenv env origExprTy lid exprBeingAssigned (origExpr, blockSeparator)
8368
+ true, id, ExplicitOrSpread.Explicit (longIdent, exprBeingAssigned)
8367
8369
8368
8370
let flds =
8369
8371
flds |> Map.change fieldId.idText (function
@@ -8382,7 +8384,8 @@ and TcCopyAndUpdateAnonRecdExpr cenv (overallTy: TType) env tpenv (isStruct, (or
8382
8384
//
8383
8385
// Keep both, but error.
8384
8386
| Some (LeftwardExplicit, dupes) ->
8385
- errorR (Error (FSComp.SR.tcAnonRecdDuplicateFieldId fieldId.idText, m))
8387
+ if not isFromNestedUpdate then
8388
+ errorR (Error (FSComp.SR.tcAnonRecdDuplicateFieldId fieldId.idText, m))
8386
8389
Some (LeftwardExplicit, (i, field) :: dupes)
8387
8390
8388
8391
// Rightward explicit field shadowing leftward spread field.
0 commit comments