Skip to content

Commit 0224665

Browse files
authored
Bugfix - underscore dot lambda conversion to Func<> in LINQ (#16339)
1 parent d079a77 commit 0224665

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9438,7 +9438,8 @@ and GetNewInferenceTypeForMethodArg (cenv: cenv) env tpenv x =
94389438
GetNewInferenceTypeForMethodArg cenv env tpenv a
94399439
| SynExpr.AddressOf (true, a, _, m) ->
94409440
mkByrefTyWithInference g (GetNewInferenceTypeForMethodArg cenv env tpenv a) (NewByRefKindInferenceType g m)
9441-
| SynExpr.Lambda (body = a) ->
9441+
| SynExpr.Lambda (body = a)
9442+
| SynExpr.DotLambda (expr = a) ->
94429443
mkFunTy g (NewInferenceType g) (GetNewInferenceTypeForMethodArg cenv env tpenv a)
94439444
| SynExpr.Quote (_, raw, a, _, _) ->
94449445
if raw then mkRawQuotedExprTy g

src/Compiler/Checking/MethodCalls.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ let InferLambdaArgsForLambdaPropagation origRhsExpr =
841841
match e with
842842
| SynExpr.Lambda (body = rest) -> 1 + loop rest
843843
| SynExpr.MatchLambda _ -> 1
844-
| SynExpr.DotLambda _ -> 1
844+
| SynExpr.DotLambda (expr = body) -> 1 + loop body
845845
| _ -> 0
846846
loop origRhsExpr
847847

tests/FSharp.Compiler.ComponentTests/Language/DotLambdaTests.fs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,20 @@ let c : string = let _ = "test" in "asd" |> _.ToString()
224224
|> withLangVersion80
225225
|> typecheck
226226
|> shouldFail
227-
|> 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.")
227+
|> 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.")
228+
229+
[<Fact>]
230+
let ``DotLambda selector converted to Func when used in LINQ`` () =
231+
FSharp """open System.Linq
232+
let _ = [""; ""; ""].Select(fun x -> x.Length)
233+
let _ = [""; ""; ""].Select(_.Length)
234+
let _ = [""; ""; ""].Select _.Length
235+
236+
let asQ = [""; ""; ""].AsQueryable()
237+
let _ = asQ.Select(fun x -> x.Length)
238+
let _ = asQ.Select(_.Length)
239+
let _ = asQ.Select _.Length
240+
"""
241+
|> withLangVersion80
242+
|> typecheck
243+
|> shouldSucceed

0 commit comments

Comments
 (0)