Skip to content

Commit 0539af7

Browse files
github-actions[bot]CopilotT-Gro
authored
Add regression test: #16154, task CE with IQueryable filters no longer throws VerificationException (#19530)
* Add regression test: #16154, task CE with IQueryable filter no longer throws VerificationException Fixes #16154 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix CI: scope issue 16154 regression test to NETCOREAPP only The VerificationException from the upcast-to-obj in the task state machine still occurs on .NET Framework due to stricter IL verification. The test passes on .NET Core where this is handled correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>
1 parent 85d7cb1 commit 0539af7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,5 +425,44 @@ if (four [ ("", 10) ]).Result <> 6 then
425425
|> compileExeAndRun
426426
|> shouldSucceed
427427

428+
// https://github.com/dotnet/fsharp/issues/16154
429+
// VerificationException still occurs on .NET Framework due to stricter IL verification;
430+
// fixed on .NET Core where the upcast-to-obj in the task state machine is handled correctly.
431+
[<FSharp.Test.FactForNETCOREAPP>]
432+
let ``Issue 16154 - task CE with IQueryable filter functions should compile and run without VerificationException`` () =
433+
FSharp """
434+
open System.Linq
435+
436+
type Shape = {x: int; y: int}
428437
438+
let returnFilter condition =
439+
task {
440+
if condition = "a" then
441+
let filter1 : IQueryable<Shape> -> IQueryable<Shape> =
442+
fun data -> data.Where(fun a -> a.x = 1)
443+
return Some filter1
444+
elif condition = "b" then
445+
let filter2 : IQueryable<Shape> -> IQueryable<Shape> =
446+
fun data -> data.Where(fun a -> a.y <> 2)
447+
return Some filter2
448+
else
449+
return None
450+
}
429451
452+
let data = [{x = 1; y = 1}; {x = 2; y = 2}].AsQueryable()
453+
let result =
454+
task {
455+
let! f1 = returnFilter "a"
456+
let! f2 = returnFilter "b"
457+
match f1, f2 with
458+
| Some filter1, Some filter2 ->
459+
return data |> filter2 |> filter1 |> Seq.toList
460+
| _ -> return []
461+
} |> (fun t -> t.GetAwaiter().GetResult())
462+
463+
if result.Length <> 1 then failwith $"unexpected result length {result.Length}"
464+
if result[0].x <> 1 then failwith $"unexpected result {result[0]}"
465+
"""
466+
|> asExe
467+
|> compileExeAndRun
468+
|> shouldSucceed

0 commit comments

Comments
 (0)