- Notifications
You must be signed in to change notification settings - Fork830
Add regression tests for FSharpPlus consumer scenarios affected by F# 9#19008
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
Copilot wants to merge2 commits intomainChoose a base branch fromcopilot/add-regression-tests-fsharp-plus
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+131 −0
Draft
Changes from1 commit
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
PrevPrevious commit
Add FSharpPlus regression tests for F# 9 issues
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
1 change: 1 addition & 0 deletionstests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletionstests/FSharp.Compiler.ComponentTests/Language/FSharpPlusRegressionTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
| namespace Language | ||
| open System | ||
| open Xunit | ||
| open FSharp.Test.ScriptHelpers | ||
| open FSharp.Compiler.Diagnostics | ||
| module FSharpPlusRegressionTests = | ||
| /// <summary> | ||
| /// Regression test for FSharpPlus issue #613 - monad.plus usage scenario. | ||
| /// This test reproduces a consumer-side failure where using monad.plus in F# 9 | ||
| /// causes compilation issues. The code should compile successfully. | ||
| /// Issue: https://github.com/fsprojects/FSharpPlus/issues/613 | ||
| /// </summary> | ||
| [<Theory>] | ||
| [<InlineData("8.0")>] | ||
| [<InlineData("preview")>] | ||
| [<InlineData("preview", "--checknulls+")>] | ||
| let ``monad.plus usage should compile successfully`` (langVersion: string, [<ParamArray>] additionalArgs: string[]) = | ||
| let allArgs = Array.concat [[| "--langversion:" + langVersion |]; additionalArgs] | ||
| use script = new FSharpScript(additionalArgs = allArgs, quiet = true) | ||
| let code = """ | ||
| // Simulated monad.plus pattern from FSharpPlus | ||
| // This pattern uses statically resolved type parameters (SRTP) for ad-hoc polymorphism | ||
| type MonadPlusClass = | ||
| static member inline MPlus (x: option<'a>, y: option<'a>) = | ||
| match x with | ||
| | Some _ -> x | ||
| | None -> y | ||
| static member inline MPlus (x: list<'a>, y: list<'a>) = x @ y | ||
| // Generic mplus function using SRTP to dispatch to appropriate implementation | ||
| let inline mplus (x: ^M) (y: ^M) : ^M = | ||
| ((^MonadPlusClass or ^M) : (static member MPlus : ^M * ^M -> ^M) (x, y)) | ||
| // Direct usage with concrete types | ||
| let testOption() = | ||
| let result : int option = mplus (Some 1) (Some 2) | ||
| printfn "Option result = %A" result | ||
| let testList() = | ||
| let result : int list = mplus [1; 2] [3; 4] | ||
| printfn "List result = %A" result | ||
| testOption() | ||
| testList() | ||
| """ | ||
| let evalResult, diagnostics = script.Eval(code) | ||
| // The code should compile successfully | ||
| match evalResult with | ||
| | Ok _ -> | ||
| // Filter out informational diagnostics | ||
| let errors = diagnostics |> Array.filter (fun d -> | ||
| d.Severity = FSharpDiagnosticSeverity.Error) | ||
| Assert.Empty(errors) | ||
| | Error ex -> | ||
| Assert.True(false, sprintf "Evaluation failed with exception: %s\nDiagnostics: %A" ex.Message diagnostics) | ||
| /// <summary> | ||
| /// Regression test for FSharpPlus issue #613 - custom ResultTBuilder scenario. | ||
| /// This test reproduces a consumer-side failure where defining a custom ResultTBuilder | ||
| /// in F# 9 causes compilation issues. The code should compile successfully. | ||
| /// Issue: https://github.com/fsprojects/FSharpPlus/issues/613 | ||
| /// </summary> | ||
| [<Theory>] | ||
| [<InlineData("8.0")>] | ||
| [<InlineData("preview")>] | ||
| [<InlineData("preview", "--checknulls+")>] | ||
| let ``custom ResultTBuilder should compile successfully`` (langVersion: string, [<ParamArray>] additionalArgs: string[]) = | ||
| let allArgs = Array.concat [[| "--langversion:" + langVersion |]; additionalArgs] | ||
| use script = new FSharpScript(additionalArgs = allArgs, quiet = true) | ||
| let code = """ | ||
| // Custom ResultTBuilder pattern from FSharpPlus | ||
| type ResultTBuilder() = | ||
| member inline _.Return(x: 'T) : Result<'T, 'Error> = Ok x | ||
| member inline _.ReturnFrom(m: Result<'T, 'Error>) : Result<'T, 'Error> = m | ||
| member inline _.Bind(m: Result<'T, 'Error>, f: 'T -> Result<'U, 'Error>) : Result<'U, 'Error> = | ||
| match m with | ||
| | Ok x -> f x | ||
| | Error e -> Error e | ||
| member inline _.Zero() : Result<unit, 'Error> = Ok () | ||
| member inline _.Combine(m1: Result<unit, 'Error>, m2: Result<'T, 'Error>) : Result<'T, 'Error> = | ||
| match m1 with | ||
| | Ok () -> m2 | ||
| | Error e -> Error e | ||
| member inline _.Delay(f: unit -> Result<'T, 'Error>) : unit -> Result<'T, 'Error> = f | ||
| member inline _.Run(f: unit -> Result<'T, 'Error>) : Result<'T, 'Error> = f() | ||
| let resultT = ResultTBuilder() | ||
| // Usage example | ||
| let compute x y = | ||
| resultT { | ||
| let! a = Ok x | ||
| let! b = Ok y | ||
| return a + b | ||
| } | ||
| // Apply the function to avoid value restriction | ||
| let testResult : Result<int, string> = compute 5 10 | ||
| // Verify result | ||
| printfn "testResult = %A" testResult | ||
| """ | ||
| let evalResult, diagnostics = script.Eval(code) | ||
| // The code should compile successfully | ||
| match evalResult with | ||
| | Ok _ -> | ||
| // Filter out informational diagnostics | ||
| let errors = diagnostics |> Array.filter (fun d -> | ||
| d.Severity = FSharpDiagnosticSeverity.Error) | ||
| Assert.Empty(errors) | ||
| | Error ex -> | ||
| Assert.True(false, sprintf "Evaluation failed with exception: %s\nDiagnostics: %A" ex.Message diagnostics) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.