Skip to content

Commit

Permalink
Do not use length if we can pattern match (dotnet#5716)
Browse files Browse the repository at this point in the history
* Do not use length if we can pattern match

* Check field count only once
  • Loading branch information
forki authored and auduchinok committed Dec 15, 2018
1 parent ed12125 commit 7da7d6c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap:Import.Import
// Method must be static, have 'Extension' attribute, must not be curried, must have at least one argument
if not minfo.IsInstance &&
not minfo.IsExtensionMember &&
minfo.NumArgs.Length = 1 &&
minfo.NumArgs.Head >= 1 &&
(match minfo.NumArgs with [x] when x >= 1 -> true | _ -> false) &&
MethInfoHasAttribute g m g.attrib_ExtensionAttribute minfo
then
let ilExtMem = ILExtMem (tcrefOfStaticClass, minfo, pri)
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ let FreshenAbstractSlot g amap m synTyparDecls absMethInfo =
let BuildFieldMap cenv env isPartial ty flds m =
let ad = env.eAccessRights
if isNil flds then invalidArg "flds" "BuildFieldMap"
let fldCount = flds.Length

let frefSets =
let allFields = flds |> List.map (fun ((_, ident), _) -> ident)
Expand All @@ -1960,7 +1961,7 @@ let BuildFieldMap cenv env isPartial ty flds m =
warning (Error(FSComp.SR.tcFieldsDoNotDetermineUniqueRecordType(), m))

// try finding a record type with the same number of fields as the ones that are given.
match tcrefs |> List.tryFind (fun tc -> tc.TrueFieldsAsList.Length = flds.Length) with
match tcrefs |> List.tryFind (fun tc -> tc.TrueFieldsAsList.Length = fldCount) with
| Some tcref -> tcref
| _ ->
// OK, there isn't a unique, good type dictated by the intersection for the field refs.
Expand Down

0 comments on commit 7da7d6c

Please sign in to comment.