@@ -1918,11 +1918,6 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ExplicitOrSpread<(Ident l
19181918 let ad = env.eAccessRights
19191919
19201920 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
19261921
19271922 let fldResolutions =
19281923 flds
@@ -7804,11 +7799,15 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, m
78047799 // we assume that parse errors were already reported
78057800 raise (ReportedError None)
78067801
7807- let ExplicitOrSpread.Explicit ((_ , fieldId), _) | ExplicitOrSpread.Spread ((_, fieldId), _) as field =
7802+ let isFromNestedUpdate , fieldId, field =
78087803 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)
78127811
78137812 let flds =
78147813 flds |> Map.change fieldId.idText (function
@@ -7827,7 +7826,8 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, m
78277826 //
78287827 // Keep both, but error.
78297828 | Some (LeftwardExplicit, dupes) ->
7830- errorR (Duplicate ("field", fieldId.idText, m))
7829+ if not isFromNestedUpdate then
7830+ errorR (Error (FSComp.SR.tcMultipleFieldsInRecord fieldId.idText, m))
78317831 Some (LeftwardExplicit, (i, field) :: dupes)
78327832
78337833 // Rightward explicit field shadowing leftward spread field.
@@ -8359,11 +8359,13 @@ and TcCopyAndUpdateAnonRecdExpr cenv (overallTy: TType) env tpenv (isStruct, (or
83598359 List.rev spreadSrcs, fieldsInOriginalOrder, tpenv
83608360
83618361 | 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 =
83638363 match synLongIdent.LongIdent with
83648364 | [] -> 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)
83678369
83688370 let flds =
83698371 flds |> Map.change fieldId.idText (function
@@ -8382,7 +8384,8 @@ and TcCopyAndUpdateAnonRecdExpr cenv (overallTy: TType) env tpenv (isStruct, (or
83828384 //
83838385 // Keep both, but error.
83848386 | 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))
83868389 Some (LeftwardExplicit, (i, field) :: dupes)
83878390
83888391 // Rightward explicit field shadowing leftward spread field.
0 commit comments