@@ -9674,23 +9674,36 @@ 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+ // Look at all branches, keeping the one
9694+ // that gives us the most syntactic information.
9695+ (loopClause a, clauses)
9696+ ||> List.fold (fun ((maxClauseDepth, _) as acc) (SynMatchClause (resultExpr = a)) ->
9697+ match loopClause a with
9698+ | clauseDepth, ty when clauseDepth > maxClauseDepth -> clauseDepth, ty
9699+ | _ -> acc)
9700+ | SynExpr.Quote (_, raw, a, _, _) ->
9701+ if raw then cont (0, mkRawQuotedExprTy g)
9702+ else loopExpr a (cont << fun (depth, ty) -> depth + 1, mkQuotedExprTy g ty)
9703+ | _ -> cont (0, NewInferenceType g)
9704+
9705+ let _depth, ty = loopExpr x id
9706+ ty
96949707
96959708and CalledMethHasSingleArgumentGroupOfThisLength n (calledMeth: MethInfo) =
96969709 match calledMeth.NumArgs with
@@ -9725,7 +9738,7 @@ and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMet
97259738and TcMethodApplication_SplitSynArguments
97269739 (cenv: cenv)
97279740 (env: TcEnv)
9728- tpenv
9741+ _tpenv
97299742 isProp
97309743 (candidates: MethInfo list)
97319744 (exprTy: OverallTy)
@@ -9753,7 +9766,7 @@ and TcMethodApplication_SplitSynArguments
97539766 else
97549767 unnamedCurriedCallerArgs, namedCurriedCallerArgs
97559768
9756- let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv env tpenv x, x.Range)
9769+ let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv x, x.Range)
97579770
97589771 let singleMethodCurriedArgs =
97599772 match candidates with
@@ -9792,7 +9805,7 @@ and TcMethodApplication_SplitSynArguments
97929805 | _ ->
97939806 let unnamedCurriedCallerArgs = unnamedCurriedCallerArgs |> List.mapSquared MakeUnnamedCallerArgInfo
97949807 let namedCurriedCallerArgs = namedCurriedCallerArgs |> List.mapSquared (fun (isOpt, nm, x) ->
9795- let ty = GetNewInferenceTypeForMethodArg cenv env tpenv x
9808+ let ty = GetNewInferenceTypeForMethodArg cenv x
97969809 // #435263: compiler crash with .net optional parameters and F# optional syntax
97979810 // named optional arguments should always have option type
97989811 // STRUCT OPTIONS: if we allow struct options as optional arguments then we should relax this and rely
0 commit comments