From 8025fd5ca6c04926428e9fc26509d205c312ee97 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 24 Nov 2023 15:13:23 +0100 Subject: [PATCH 1/3] dotlambda func conversion --- src/Compiler/Checking/CheckExpressions.fs | 3 ++- src/Compiler/Checking/MethodCalls.fs | 2 +- .../Language/DotLambdaTests.fs | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 9f31d7f600e..a8bb8570206 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9438,7 +9438,8 @@ and GetNewInferenceTypeForMethodArg (cenv: cenv) env tpenv x = 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.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 diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index d7e09b86aeb..4878c66511c 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -841,7 +841,7 @@ let InferLambdaArgsForLambdaPropagation origRhsExpr = match e with | SynExpr.Lambda (body = rest) -> 1 + loop rest | SynExpr.MatchLambda _ -> 1 - | SynExpr.DotLambda _ -> 1 + | SynExpr.DotLambda (expr = body) -> 1 + loop body | _ -> 0 loop origRhsExpr diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs index f0e5c77e865..f3dc8327456 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs @@ -224,4 +224,13 @@ let c : string = let _ = "test" in "asd" |> _.ToString() |> withLangVersion80 |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 3570, Line 3, Col 43, Line 3, Col 44, "The meaning of _ is ambiguous here. It cannot be used for a discarded variable and a function shorthand in the same scope.") \ No newline at end of file + |> withSingleDiagnostic (Warning 3570, Line 3, Col 43, Line 3, Col 44, "The meaning of _ is ambiguous here. It cannot be used for a discarded variable and a function shorthand in the same scope.") + +[] +let ``DotLambda selector converted to Func when used in LINQ`` () = + FSharp """open System.Linq +let _ = [""; ""; ""].Select(fun x -> x.Length) +let _ = [""; ""; ""].Select(_.Length)""" + |> withLangVersion80 + |> typecheck + |> shouldSucceed \ No newline at end of file From 22fa060ee88006acd1f39c608b1a279c622d1f15 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 24 Nov 2023 15:52:16 +0100 Subject: [PATCH 2/3] Version without parens also works --- .../FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs index f3dc8327456..0b0c815a181 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs @@ -230,7 +230,8 @@ let c : string = let _ = "test" in "asd" |> _.ToString() let ``DotLambda selector converted to Func when used in LINQ`` () = FSharp """open System.Linq let _ = [""; ""; ""].Select(fun x -> x.Length) -let _ = [""; ""; ""].Select(_.Length)""" +let _ = [""; ""; ""].Select(_.Length) +let _ = [""; ""; ""].Select _.Length""" |> withLangVersion80 |> typecheck |> shouldSucceed \ No newline at end of file From 991ec82d575def4857a12856c86216f6d434a564 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 24 Nov 2023 16:38:39 +0100 Subject: [PATCH 3/3] queryable also works --- .../Language/DotLambdaTests.fs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs index 0b0c815a181..ad9b8fe7461 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs @@ -231,7 +231,13 @@ let ``DotLambda selector converted to Func when used in LINQ`` () = FSharp """open System.Linq let _ = [""; ""; ""].Select(fun x -> x.Length) let _ = [""; ""; ""].Select(_.Length) -let _ = [""; ""; ""].Select _.Length""" +let _ = [""; ""; ""].Select _.Length + +let asQ = [""; ""; ""].AsQueryable() +let _ = asQ.Select(fun x -> x.Length) +let _ = asQ.Select(_.Length) +let _ = asQ.Select _.Length +""" |> withLangVersion80 |> typecheck |> shouldSucceed \ No newline at end of file