Skip to content

Commit b8ea540

Browse files
authored
Merge pull request dotnet#6 from brianrourkeboll/all-branches
All branches
2 parents 516cf11 + f393219 commit b8ea540

2 files changed

Lines changed: 56 additions & 21 deletions

File tree

‎src/Compiler/Checking/Expressions/CheckExpressions.fs‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

96959708
and CalledMethHasSingleArgumentGroupOfThisLength n (calledMeth: MethInfo) =
96969709
match calledMeth.NumArgs with
@@ -9725,7 +9738,7 @@ and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMet
97259738
and 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

‎tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadResolutionUsingFunction.fs‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,39 @@ let ae = new AggregateException()
44
ae.Handle(fun e ->
55
match e with
66
| :? OperationCanceledException -> true
7-
| _ -> false
7+
| _ -> false
88
)
99

1010
ae.Handle(function
1111
| :? OperationCanceledException -> true
12-
| _ -> false
12+
| _ -> false
1313
)
1414

1515
ae.Handle(
1616
Func<exn,bool>(
1717
function
1818
| :? OperationCanceledException -> true
19-
| _ -> false
20-
))
19+
| _ -> false
20+
))
21+
22+
module M1 =
23+
type T =
24+
static member M (_ : Func<int, exn, int>) = ()
25+
26+
T.M (function _ -> function :? ArgumentException -> 3 | _ -> 4)
27+
T.M (function 0 -> (function _ -> 3) | _ -> function :? ArgumentException -> 3 | _ -> 4)
28+
29+
module M2 =
30+
type T =
31+
static member M (_ : Func<int, int, int>) = ()
32+
33+
T.M (function 0 -> (function _ -> 1) | _ -> (function 0 -> 3 | _ -> 4))
34+
T.M (function 0 -> id | _ -> (function 0 -> 3 | _ -> 4))
35+
T.M (function 0 -> (function 0 -> 3 | _ -> 4) | _ -> id)
36+
37+
module M3 =
38+
type T =
39+
static member M (_ : Func<int, int, int, int>) = ()
40+
41+
T.M (function 0 -> (function 0 -> (function 0 -> 1 | _ -> 0) | _ -> (function 0 -> 2 | _ -> 3)) | _ -> (function 0 -> (function _ -> 3) | _ -> (function 3 -> 4 | _ -> 5)))
42+
T.M (function 0 -> (function 0 -> id | _ -> (function 0 -> 2 | _ -> 3)) | _ -> (function 0 -> (function _ -> 3) | _ -> (function 3 -> 4 | _ -> 5)))

0 commit comments

Comments
 (0)