Skip to content

Commit

Permalink
Inline isRecdTy (#8274)
Browse files Browse the repository at this point in the history
  • Loading branch information
forki authored and TIHan committed Jan 19, 2020
1 parent 7b3c2af commit e07132b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,11 +3214,12 @@ let ResolveFieldPrim sink (ncenv: NameResolver) nenv ad ty (mp, id: Ident) allFi
|> ListSet.setify (fun fref1 fref2 -> tyconRefEq g fref1.TyconRef fref2.TyconRef)
|> List.map (fun x -> ResolutionInfo.Empty, FieldResolution(x, false))

if isAppTy g ty then
match tryDestAppTy g ty with
| ValueSome tcref ->
match ncenv.InfoReader.TryFindRecdOrClassFieldInfoOfType(id.idText, m, ty) with
| ValueSome (RecdFieldInfo(_, rfref)) -> [ResolutionInfo.Empty, FieldResolution(rfref, false)]
| _ ->
if isRecdTy g ty then
if tcref.IsRecordTycon then
// record label doesn't belong to record type -> suggest other labels of same record
let suggestLabels (addToBuffer: string -> unit) =
for label in SuggestOtherLabelsOfSameRecordType g nenv ty id allFields do
Expand All @@ -3229,7 +3230,7 @@ let ResolveFieldPrim sink (ncenv: NameResolver) nenv ad ty (mp, id: Ident) allFi
error(ErrorWithSuggestions(errorText, m, id.idText, suggestLabels))
else
lookup()
else
| _ ->
lookup()
| _ ->
let lid = (mp@[id])
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6876,7 +6876,7 @@ and TcObjectExpr cenv overallTy env tpenv (synObjTy, argopt, binds, extraImpls,
match tryDestAppTy cenv.g objTy with
| ValueNone -> error(Error(FSComp.SR.tcNewMustBeUsedWithNamedType(), mNewExpr))
| ValueSome tcref ->
let isRecordTy = isRecdTy cenv.g objTy
let isRecordTy = tcref.IsRecordTycon
if not isRecordTy && not (isInterfaceTy cenv.g objTy) && isSealedTy cenv.g objTy then errorR(Error(FSComp.SR.tcCannotCreateExtensionOfSealedType(), mNewExpr))

CheckSuperType cenv objTy synObjTy.Range
Expand Down Expand Up @@ -7265,12 +7265,12 @@ and TcAnonRecdExpr cenv overallTy env tpenv (isStruct, optOrigSynExpr, unsortedF
for (i, id) in Array.indexed anonInfo.SortedIds do
yield id, Choice2Of2 (mkAnonRecdFieldGetViaExprAddr (anonInfo, oldveaddr, tinst, i, mOrigExpr))
| ValueNone ->
if isRecdTy cenv.g origExprTy then
let tcref, tinst = destAppTy cenv.g origExprTy
match tryAppTy cenv.g origExprTy with
| ValueSome(tcref, tinst) when tcref.IsRecordTycon ->
let fspecs = tcref.Deref.TrueInstanceFieldsAsList
for fspec in fspecs do
yield fspec.Id, Choice2Of2 (mkRecdFieldGetViaExprAddr (oldveaddr, tcref.MakeNestedRecdFieldRef fspec, tinst, mOrigExpr))
else
| _ ->
error (Error (FSComp.SR.tcCopyAndUpdateNeedsRecordType(), mOrigExpr)) |]
|> Array.distinctBy (fst >> textOfId)

Expand Down

0 comments on commit e07132b

Please sign in to comment.