Skip to content

Some more active pattern error message improvements + tests - #17186

Merged
psfinaki merged 8 commits into
dotnet:mainfrom
brianrourkeboll:active-pattern-msgs
May 24, 2024
Merged

Some more active pattern error message improvements + tests#17186
psfinaki merged 8 commits into
dotnet:mainfrom
brianrourkeboll:active-pattern-msgs

Conversation

@brianrourkeboll

@brianrourkebollbrianrourkeboll commented May 20, 2024

Copy link
Copy Markdown
Contributor

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
    letexpr2=2match1with 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

github-actionsBot commented May 20, 2024

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/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 ownerMay 20, 2024 19:19

@psfinakipsfinaki left a comment

Copy link
Copy Markdown
Contributor

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 freeto 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

@brianrourkeboll@psfinaki@edgarfgp@T-Gro