Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function implicit conversion the same way as fun x #17487

Merged
merged 22 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
725e8cb
`function` implicit conversion the same way as `fun x`
edgarfgp Aug 4, 2024
bfcd2d8
release notes
edgarfgp Aug 4, 2024
3932861
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 4, 2024
24b789b
Update src/Compiler/Checking/Expressions/CheckExpressions.fs
edgarfgp Aug 5, 2024
5bb9415
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 5, 2024
358d296
More test cases
edgarfgp Aug 5, 2024
da5d09e
Revert "More test cases"
edgarfgp Aug 5, 2024
516cf11
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 6, 2024
581be73
Handle all branches of match-lambdas
brianrourkeboll Aug 6, 2024
589a829
Add a couple more match-lambda tests
brianrourkeboll Aug 6, 2024
5ed6fce
One more
brianrourkeboll Aug 6, 2024
f393219
Add comment
brianrourkeboll Aug 6, 2024
b8ea540
Merge pull request #6 from brianrourkeboll/all-branches
edgarfgp Aug 6, 2024
b7da421
Merge branch 'main' into fix-function-implicit-convertion
vzarytovskii Aug 6, 2024
81b75fd
Struct tuples
brianrourkeboll Aug 7, 2024
9554c3c
Merge pull request #7 from brianrourkeboll/struct-tuples
edgarfgp Aug 7, 2024
bc4cb06
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 7, 2024
939707f
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 7, 2024
820352c
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 8, 2024
7146e29
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 9, 2024
7003763
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 9, 2024
95214f5
Merge branch 'main' into fix-function-implicit-convertion
edgarfgp Aug 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Optimize simple mappings in comprehensions when the body of the mapping has `let`-bindings and/or sequential expressions before a single yield. ([PR #17419](https://github.com/dotnet/fsharp/pull/17419))
* C# protected property can be assigned in F# inherit constructor call. ([Issue #13299](https://github.com/dotnet/fsharp/issues/13299), [PR #17391](https://github.com/dotnet/fsharp/pull/17391))
* MethodAccessException on equality comparison of a record with private fields. ([Issue #17447](https://github.com/dotnet/fsharp/issues/17447), [PR #17391](https://github.com/dotnet/fsharp/pull/17467))
* Fix `function` implicit conversion. ([Issue #7401](https://github.com/dotnet/fsharp/issues/7401), [PR #17487](https://github.com/dotnet/fsharp/pull/17487))
* Compiler fails to recognise namespace in FQN with enabled GraphBasedChecking. ([Issue #17508](https://github.com/dotnet/fsharp/issues/17508), [PR #17510](https://github.com/dotnet/fsharp/pull/17510))

### Added
Expand Down
46 changes: 30 additions & 16 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9672,22 +9672,36 @@ and TcMethodApplicationThen
PropagateThenTcDelayed cenv overallTy env tpenv mWholeExpr (MakeApplicableExprNoFlex cenv expr) exprTy atomicFlag delayed

/// Infer initial type information at the callsite from the syntax of an argument, prior to overload resolution.
and GetNewInferenceTypeForMethodArg (cenv: cenv) env tpenv x =
and GetNewInferenceTypeForMethodArg (cenv: cenv) x =

let g = cenv.g

match x with
| SynExprParen(a, _, _, _) ->
GetNewInferenceTypeForMethodArg cenv env tpenv a
| SynExpr.AddressOf (true, a, _, m) ->
mkByrefTyWithInference g (GetNewInferenceTypeForMethodArg cenv env tpenv a) (NewByRefKindInferenceType g m)
| SynExpr.Lambda (body = a)
| SynExpr.DotLambda (expr = a) ->
mkFunTy g (NewInferenceType g) (GetNewInferenceTypeForMethodArg cenv env tpenv a)
| SynExpr.Quote (_, raw, a, _, _) ->
if raw then mkRawQuotedExprTy g
else mkQuotedExprTy g (GetNewInferenceTypeForMethodArg cenv env tpenv a)
| _ -> NewInferenceType g
let rec loopExpr expr cont : struct (_ * _) =
match expr with
| SynExprParen (a, _, _, _) ->
loopExpr a cont
| SynExpr.AddressOf (true, a, _, m) ->
loopExpr a (cont << fun struct (depth, ty) -> depth + 1, mkByrefTyWithInference g ty (NewByRefKindInferenceType g m))
| SynExpr.Lambda (body = a)
| SynExpr.DotLambda (expr = a) ->
loopExpr a (cont << fun struct (depth, ty) -> depth + 1, mkFunTy g (NewInferenceType g) ty)
| SynExpr.MatchLambda (matchClauses = SynMatchClause (resultExpr = a) :: clauses) ->
let loopClause a = loopExpr a (cont << fun struct (depth, ty) -> depth + 1, mkFunTy g (NewInferenceType g) ty)

// Look at all branches, keeping the one
// that gives us the most syntactic information.
(loopClause a, clauses)
||> List.fold (fun ((maxClauseDepth, _) as acc) (SynMatchClause (resultExpr = a)) ->
match loopClause a with
| clauseDepth, ty when clauseDepth > maxClauseDepth -> clauseDepth, ty
| _ -> acc)
| SynExpr.Quote (_, raw, a, _, _) ->
if raw then cont (0, mkRawQuotedExprTy g)
else loopExpr a (cont << fun struct (depth, ty) -> depth + 1, mkQuotedExprTy g ty)
| _ -> cont (0, NewInferenceType g)

let struct (_depth, ty) = loopExpr x id
ty

and CalledMethHasSingleArgumentGroupOfThisLength n (calledMeth: MethInfo) =
match calledMeth.NumArgs with
Expand Down Expand Up @@ -9722,7 +9736,7 @@ and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMet
and TcMethodApplication_SplitSynArguments
(cenv: cenv)
(env: TcEnv)
tpenv
_tpenv
isProp
(candidates: MethInfo list)
(exprTy: OverallTy)
Expand Down Expand Up @@ -9750,7 +9764,7 @@ and TcMethodApplication_SplitSynArguments
else
unnamedCurriedCallerArgs, namedCurriedCallerArgs

let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv env tpenv x, x.Range)
let MakeUnnamedCallerArgInfo x = (x, GetNewInferenceTypeForMethodArg cenv x, x.Range)

let singleMethodCurriedArgs =
match candidates with
Expand Down Expand Up @@ -9789,7 +9803,7 @@ and TcMethodApplication_SplitSynArguments
| _ ->
let unnamedCurriedCallerArgs = unnamedCurriedCallerArgs |> List.mapSquared MakeUnnamedCallerArgInfo
let namedCurriedCallerArgs = namedCurriedCallerArgs |> List.mapSquared (fun (isOpt, nm, x) ->
let ty = GetNewInferenceTypeForMethodArg cenv env tpenv x
let ty = GetNewInferenceTypeForMethodArg cenv x
// #435263: compiler crash with .net optional parameters and F# optional syntax
// named optional arguments should always have option type
// STRUCT OPTIONS: if we allow struct options as optional arguments then we should relax this and rely
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
open System
let ae = new AggregateException()

ae.Handle(fun e ->
match e with
| :? OperationCanceledException -> true
| _ -> false
)

ae.Handle(function
| :? OperationCanceledException -> true
| _ -> false
)

ae.Handle(
Func<exn,bool>(
function
| :? OperationCanceledException -> true
| _ -> false
))

module M1 =
type T =
static member M (_ : Func<int, exn, int>) = ()

T.M (function _ -> function :? ArgumentException -> 3 | _ -> 4)
T.M (function 0 -> (function _ -> 3) | _ -> function :? ArgumentException -> 3 | _ -> 4)

module M2 =
type T =
static member M (_ : Func<int, int, int>) = ()

T.M (function 0 -> (function _ -> 1) | _ -> (function 0 -> 3 | _ -> 4))
T.M (function 0 -> id | _ -> (function 0 -> 3 | _ -> 4))
T.M (function 0 -> (function 0 -> 3 | _ -> 4) | _ -> id)

module M3 =
type T =
static member M (_ : Func<int, int, int, int>) = ()

T.M (function 0 -> (function 0 -> (function 0 -> 1 | _ -> 0) | _ -> (function 0 -> 2 | _ -> 3)) | _ -> (function 0 -> (function _ -> 3) | _ -> (function 3 -> 4 | _ -> 5)))
T.M (function 0 -> (function 0 -> id | _ -> (function 0 -> 2 | _ -> 3)) | _ -> (function 0 -> (function _ -> 3) | _ -> (function 3 -> 4 | _ -> 5)))
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ module MemberDefinitions_OverloadingMembers =
|> withDefines ["TOO_GENERIC"]
|> verifyCompileAndRun
|> shouldSucceed

[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"OverloadResolutionUsingFunction.fs"|])>]
let ``OverloadResolutionUsingFunction_fs`` compilation =
compilation
|> verifyCompileAndRun
|> shouldSucceed
Loading