Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 854f080

Browse files
authored
Remove limitations on custom operation overloads
- Check 1:1 by operation/method names instead of count - Remove arg count check
1 parent a3d131e commit 854f080

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/fsharp/TypeChecker.fs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7165,17 +7165,24 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv
71657165

71667166
Some (nm, maintainsVarSpaceUsingBind, maintainsVarSpace, allowInto, isLikeZip, isLikeJoin, isLikeGroupJoin, joinConditionWord, methInfo))
71677167

7168-
let customOperationMethodsIndexedByKeyword =
7168+
let customOperationMethodsIndexedByKeyword =
71697169
customOperationMethods
71707170
|> Seq.groupBy (fun (nm, _, _, _, _, _, _, _, _) -> nm)
7171-
|> Seq.map (fun (nm, g) -> (nm, Seq.toList g))
7171+
|> Seq.map (fun (nm, g) ->
7172+
(nm,
7173+
g
7174+
|> Seq.distinctBy (fun (_, _, _, _, _, _, _, _, methInfo) -> methInfo.LogicalName)
7175+
|> Seq.toList))
71727176
|> dict
71737177

71747178
// Check for duplicates by method name (keywords and method names must be 1:1)
71757179
let customOperationMethodsIndexedByMethodName =
71767180
customOperationMethods
7177-
|> Seq.groupBy (fun (_, _, _, _, _, _, _, _, methInfo) -> methInfo.LogicalName)
7178-
|> Seq.map (fun (nm, g) -> (nm, Seq.toList g))
7181+
|> Seq.groupBy (fun (_, _, _, _, _, _, _, _, methInfo) -> methInfo.LogicalName)
7182+
|> Seq.map (fun (nm, g) ->
7183+
(nm,
7184+
g
7185+
|> Seq.distinctBy (fun (nm, _, _, _, _, _, _, _, _) -> nm) |> Seq.toList ))
71797186
|> dict
71807187

71817188

@@ -7809,18 +7816,12 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv
78097816
let maintainsVarSpace = customOperationMaintainsVarSpace nm
78107817
let maintainsVarSpaceUsingBind = customOperationMaintainsVarSpaceUsingBind nm
78117818

7812-
let expectedArgCount = expectedArgCountForCustomOperator nm
7813-
78147819
let dataCompAfterOp =
78157820
match opExpr with
78167821
| StripApps(SingleIdent nm, args) ->
7817-
if args.Length = expectedArgCount then
7818-
// Check for the [<ProjectionParameter>] attribute on each argument position
7819-
let args = args |> List.mapi (fun i arg -> if isCustomOperationProjectionParameter (i+1) nm then SynExpr.Lambda (false, false, varSpaceSimplePat, arg, arg.Range.MakeSynthetic()) else arg)
7820-
mkSynCall methInfo.DisplayName mClause (dataCompPrior :: args)
7821-
else
7822-
errorR(Error(FSComp.SR.tcCustomOperationHasIncorrectArgCount(nm.idText, expectedArgCount, args.Length), nm.idRange))
7823-
mkSynCall methInfo.DisplayName mClause ([ dataCompPrior ] @ List.init expectedArgCount (fun i -> arbExpr("_arg" + string i, mClause)))
7822+
// Check for the [<ProjectionParameter>] attribute on each argument position
7823+
let args = args |> List.mapi (fun i arg -> if isCustomOperationProjectionParameter (i+1) nm then SynExpr.Lambda (false, false, varSpaceSimplePat, arg, arg.Range.MakeSynthetic()) else arg)
7824+
mkSynCall methInfo.DisplayName mClause (dataCompPrior :: args)
78247825
| _ -> failwith "unreachable"
78257826

78267827
match optionalCont with

0 commit comments

Comments
 (0)