Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more active pattern error message improvements + tests #17186

Merged
merged 8 commits into from
May 24, 2024

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.
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
Member

@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!

@psfinaki psfinaki merged commit 958ce12 into dotnet:main May 24, 2024
30 checks passed
@brianrourkeboll brianrourkeboll deleted the active-pattern-msgs branch May 24, 2024 11:33
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