Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 16, 2025

This PR adds regression tests documenting two consumer-side failures reported in FSharpPlus issue #613 that occur with F# 9.

Overview

The tests reproduce real-world FSharpPlus patterns that currently fail to compile in F# 9, serving as regression tests to track when these issues are resolved in the compiler.

Test Scenarios

1. monad.plus SRTP Pattern (Currently Failing)

Tests the use of statically resolved type parameters (SRTP) for ad-hoc polymorphism with overloaded static members:

type MonadPlusClass =
    static member inline MPlus (x: option<'a>, y: option<'a>) = ...
    static member inline MPlus (x: list<'a>, y: list<'a>) = ...

let inline mplus (x: ^M) (y: ^M) : ^M =
    ((^MonadPlusClass or ^M) : (static member MPlus : ^M * ^M -> ^M) (x, y))

let result : int option = mplus (Some 1) (Some 2)  // Fails with type constraint mismatch

Current Error: Type constraint mismatch when applying the default type 'obj' for a type inference variable. None of the types 'obj, int option' support the operator 'MPlus'

2. Custom ResultTBuilder (Currently Passing)

Tests defining a custom computation expression builder for Result types:

type ResultTBuilder() =
    member inline _.Return(x: 'T) : Result<'T, 'Error> = Ok x
    member inline _.Bind(m, f) = ...
    // ... other members

let resultT = ResultTBuilder()
let compute x y =
    resultT {
        let! a = Ok x
        let! b = Ok y
        return a + b
    }

This scenario currently works correctly in F# 9.

Test Configuration

Each test runs with three compiler configurations:

  • --langversion:8.0 - F# 8 baseline
  • --langversion:preview - F# 9 preview
  • --langversion:preview --checknulls+ - F# 9 preview with nullable reference types

Implementation Details

  • Uses FSharpScript interactive API for scripting evaluation
  • Tests are structured as xUnit Theory tests with InlineData parameters
  • Located in tests/FSharp.Compiler.ComponentTests/Language/FSharpPlusRegressionTests.fs
  • Tests assert compilation success, documenting expected behavior

Test Results

Test run summary:
- monad.plus usage (3 scenarios): ❌ All failing - documents SRTP regression
- ResultTBuilder usage (3 scenarios): ✅ All passing - pattern works correctly

The failing monad.plus tests will serve as indicators when the SRTP resolution issue is fixed in the F# compiler.

Running the Tests

# Run all FSharpPlus regression tests
dotnet test tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj \
    --filter "FullyQualifiedName~FSharpPlusRegressionTests"

# Run specific test
dotnet test tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj \
    --filter "FullyQualifiedName~monad.plus"

Related Issues

Original prompt

Add regression tests for FSharpPlus consumer scenarios affected by F# 9. These tests should reproduce two consumer-side failures described in the last comment of fsprojects/FSharpPlus#613: (1) usage of monad.plus, and (2) defining a custom ResultTBuilder. For each, write a Theory test with InlineData that runs against three compiler settings: (a) --langversion:8, (b) --langversion:preview, (c) --langversion:preview with --checknulls+ and --checknulls-. The tests should use the FSharpScript interactive scripting API, and should assert compilation success (i.e., as if the code should work), even though they are expected to fail with current F# 9 builds. Include collapsible markdown instructions in the PR body, detailing exactly what, where, and how is being tested.

This pull request was created as a result of the following prompt from Copilot chat.

Add regression tests for FSharpPlus consumer scenarios affected by F# 9. These tests should reproduce two consumer-side failures described in the last comment of fsprojects/FSharpPlus#613: (1) usage of monad.plus, and (2) defining a custom ResultTBuilder. For each, write a Theory test with InlineData that runs against three compiler settings: (a) --langversion:8, (b) --langversion:preview, (c) --langversion:preview with --checknulls+ and --checknulls-. The tests should use the FSharpScript interactive scripting API, and should assert compilation success (i.e., as if the code should work), even though they are expected to fail with current F# 9 builds. Include collapsible markdown instructions in the PR body, detailing exactly what, where, and how is being tested.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Add regression tests for FSharpPlus consumer scenarios Add regression tests for FSharpPlus consumer scenarios affected by F# 9 Oct 16, 2025
@Copilot Copilot AI requested a review from T-Gro October 16, 2025 09:54
Copilot finished work on behalf of T-Gro October 16, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants