From 0b1e680ffe8be9a016ebdb96f6c905c1083d447c Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 4 Aug 2024 18:28:18 +0100 Subject: [PATCH] `function` implicit conversion the same way as `fun x` --- .../Checking/Expressions/CheckExpressions.fs | 2 ++ .../OverloadResolutionUsingFunction.fs | 13 +++++++++++++ .../OverloadingMembers/OverloadingMembers.fs | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadResolutionUsingFunction.fs diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 2b3d9e7f6c66..38d2b69cb709 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -9685,6 +9685,8 @@ and GetNewInferenceTypeForMethodArg (cenv: cenv) env tpenv x = | SynExpr.Lambda (body = a) | SynExpr.DotLambda (expr = a) -> mkFunTy g (NewInferenceType g) (GetNewInferenceTypeForMethodArg cenv env tpenv a) + | SynExpr.MatchLambda _ -> + mkFunTy g (NewInferenceType g) (NewInferenceType g) | SynExpr.Quote (_, raw, a, _, _) -> if raw then mkRawQuotedExprTy g else mkQuotedExprTy g (GetNewInferenceTypeForMethodArg cenv env tpenv a) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadResolutionUsingFunction.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadResolutionUsingFunction.fs new file mode 100644 index 000000000000..1f4825cb6bff --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadResolutionUsingFunction.fs @@ -0,0 +1,13 @@ +open System +let ae = new AggregateException() + +ae.Handle(fun e -> + match e with + | :? OperationCanceledException -> true + | _ -> false + ) + +ae.Handle(function + | :? OperationCanceledException -> true + | _ -> false + ) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadingMembers.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadingMembers.fs index 1bc2d3322477..e0b4c824187d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadingMembers.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/OverloadingMembers/OverloadingMembers.fs @@ -229,3 +229,9 @@ module MemberDefinitions_OverloadingMembers = |> withDefines ["TOO_GENERIC"] |> verifyCompileAndRun |> shouldSucceed + + [] + let ``OverloadResolutionUsingFunction_fs`` compilation = + compilation + |> verifyCompileAndRun + |> shouldSucceed