Skip to content

Conversation

@brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented May 20, 2024

Description

Followup to #16846 (thanks for that, @Tangent-90!).

  • Don't imply that a pattern argument is needed when it may (and should) be omitted.

    E.g., for

    let (|P|) (expr1 : int) = P
    let expr2 = 2
    match 1 with P expr2 pat -> ()

    the error was originally

    error FS0001: This expression was expected to have type 'int -> 'a' but here has type 'unit'
    

    and after Add error tcActivePatternArgumentCountNotMatch #16846 became

    error FS3868: This active pattern expects exactly one pattern argument, e.g., 'P pat'.
    

    which was technically correct but encouraged adding an explicit pattern for unit, which is normally omitted.

    The error is now instead

    error FS3868: This active pattern does not expect any arguments, i.e., it should be used like 'P' instead of 'P x'.
    
  • A typar with (most kinds of) constraints cannot be unit. Knowing this lets us use the improved error messages in more scenarios.

  • Add more comprehensive tests for active pattern arg count error messages. They're not truly comprehensive — there are more fun combinations to try, like val (|P|) : int -> bool (as opposed to val (|P|_|) : int -> bool), val (|P|_|) : int -> bool option, etc., etc.

    Screenshot 2024-05-20 130346

Checklist

  • Test cases added.
  • Release notes entry updated.

* Don't imply that a pattern argument is needed when it may (and should)
  be omitted.

* A typar with (most kinds of) constraints cannot be unit.

* Add more comprehensive tests for active pattern arg count error
  messages.
@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

@brianrourkeboll brianrourkeboll marked this pull request as ready for review May 20, 2024 19:19
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner May 20, 2024 19:19
Copy link
Contributor

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work and great tests, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants