@@ -9674,23 +9674,34 @@ and TcMethodApplicationThen
96749674 PropagateThenTcDelayed cenv overallTy env tpenv mWholeExpr (MakeApplicableExprNoFlex cenv expr) exprTy atomicFlag delayed
96759675
96769676/// Infer initial type information at the callsite from the syntax of an argument, prior to overload resolution.
9677- and GetNewInferenceTypeForMethodArg (cenv: cenv) env tpenv x =
9677+ and GetNewInferenceTypeForMethodArg (cenv: cenv) x =
96789678
96799679 let g = cenv.g
96809680
9681- match x with
9682- | SynExprParen(a, _, _, _) ->
9683- GetNewInferenceTypeForMethodArg cenv env tpenv a
9684- | SynExpr.AddressOf (true, a, _, m) ->
9685- mkByrefTyWithInference g (GetNewInferenceTypeForMethodArg cenv env tpenv a) (NewByRefKindInferenceType g m)
9686- | SynExpr.Lambda (body = a)
9687- | SynExpr.DotLambda (expr = a)
9688- | SynExpr.MatchLambda (matchClauses = SynMatchClause (resultExpr = a) :: _) ->
9689- mkFunTy g (NewInferenceType g) (GetNewInferenceTypeForMethodArg cenv env tpenv a)
9690- | SynExpr.Quote (_, raw, a, _, _) ->
9691- if raw then mkRawQuotedExprTy g
9692- else mkQuotedExprTy g (GetNewInferenceTypeForMethodArg cenv env tpenv a)
9693- | _ -> NewInferenceType g
9681+ let rec loopExpr expr cont =
9682+ match expr with
9683+ | SynExprParen (a, _, _, _) ->
9684+ loopExpr a cont
9685+ | SynExpr.AddressOf (true, a, _, m) ->
9686+ loopExpr a (cont << fun (depth, ty) -> depth + 1, mkByrefTyWithInference g ty (NewByRefKindInferenceType g m))
9687+ | SynExpr.Lambda (body = a)
9688+ | SynExpr.DotLambda (expr = a) ->
9689+ loopExpr a (cont << fun (depth, ty) -> depth + 1, mkFunTy g (NewInferenceType g) ty)
9690+ | SynExpr.MatchLambda (matchClauses = SynMatchClause (resultExpr = a) :: clauses) ->
9691+ let loopClause a = loopExpr a (cont << fun (depth, ty) -> depth + 1, mkFunTy g (NewInferenceType g) ty)
9692+
9693+ (loopClause a, clauses)
9694+ ||> List.fold (fun ((maxClauseDepth, _) as acc) (SynMatchClause (resultExpr = a)) ->
9695+ match loopClause a with
9696+ | clauseDepth, ty when clauseDepth > maxClauseDepth -> clauseDepth, ty
9697+ | _ -> acc)
9698+ | SynExpr.Quote (_, raw, a, _, _) ->
9699+ if raw then cont (0, mkRawQuotedExprTy g)
9700+ else loopExpr a (cont << fun (depth, ty) -> depth + 1, mkQuotedExprTy g ty)
9701+ | _ -> cont (0, NewInferenceType g)
9702+
9703+ let _depth, ty = loopExpr x id
9704+ ty
96949705
96959706and CalledMethHasSingleArgumentGroupOfThisLength n (calledMeth: MethInfo) =
96969707 match calledMeth.NumArgs with
@@ -9725,7 +9736,7 @@ and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMet
97259736and TcMethodApplication_SplitSynArguments
97269737 (cenv: cenv)
97279738 (env: TcEnv)
9728- tpenv
9739+ _tpenv
97299740 isProp
97309741 (candidates: MethInfo list)
97319742 (exprTy: OverallTy)
@@ -9753,7 +9764,7 @@ and TcMethodApplication_SplitSynArguments
97539764 else
97549765 unnamedCurriedCallerArgs, namedCurriedCallerArgs
97559766
9756- let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv env tpenv x, x.Range)
9767+ let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv x, x.Range)
97579768
97589769 let singleMethodCurriedArgs =
97599770 match candidates with
@@ -9792,7 +9803,7 @@ and TcMethodApplication_SplitSynArguments
97929803 | _ ->
97939804 let unnamedCurriedCallerArgs = unnamedCurriedCallerArgs |> List.mapSquared MakeUnnamedCallerArgInfo
97949805 let namedCurriedCallerArgs = namedCurriedCallerArgs |> List.mapSquared (fun (isOpt, nm, x) ->
9795- let ty = GetNewInferenceTypeForMethodArg cenv env tpenv x
9806+ let ty = GetNewInferenceTypeForMethodArg cenv x
97969807 // #435263: compiler crash with .net optional parameters and F# optional syntax
97979808 // named optional arguments should always have option type
97989809 // STRUCT OPTIONS: if we allow struct options as optional arguments then we should relax this and rely
0 commit comments