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 #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.
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
the error was originally
and after #16846 became
which was technically correct but encouraged adding an explicit pattern for
unit
, which is normally omitted.The error is now instead
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 toval (|P|_|) : int -> bool
),val (|P|_|) : int -> bool option
, etc., etc.Checklist