Uh oh!
There was an error while loading. Please reload this page.
Add error tcActivePatternArgumentCountNotMatch - #16846
Conversation
❗ Release notes required
|
vzarytovskii
commented
Mar 12, 2024
vzarytovskii
commented
Mar 12, 2024
I think "return value" works, however "1 return value" in the error message looks a bit awkward. |
T-Gro
commented
Mar 12, 2024
My feedback for the wording: For the return value, I would use the wording: |
ijklam
commented
Mar 12, 2024
What about this? For parametrized single case active pattern and partial active pattern: This active pattern requires %d parameter(s) and returns %d value, but the usage here matches %d argument(s) and %d return value. For else: This active pattern returns %d value, but the usage here matches %d return value(s). |
T-Gro
commented
Mar 18, 2024
That looks better to me. |
psfinaki
commented
Apr 19, 2024
It's a good idea to improve this error. At the same time, as a non-user of active patterns, I got lost even with the new message. |
brianrourkeboll
commented
Apr 23, 2024
@Tangent-90
I think this is a pretty solid improvement over the status quo. I guess since we do have the expected number of expression and pattern arguments available to us, we could in theory even offer something like I wonder whether it would be worth doing something like: // Use a prebuilt expr args string for these that has an example with the actual number of args."This active pattern expects %d expression argument(s), e.g., '%s%s'.""This active pattern expects %d expression argument(s) and a pattern argument, e.g., '%s%s pat'."and letfmtExprArgs paramCount =let recloop i (sb:StringBuilder)=letcutoff=10if i > paramCount then sb.ToString()elif i > cutoff then sb.Append("...").ToString()else loop (i +1)(sb.Append(" e").Append i)
loop 1(StringBuilder())letmsg=match paramCount, returnCount with|0,0-> FSComp.SR.tcActivePatternArgsCountNotMatchNoArgsNoPat(caseName, caseName)|0,_-> FSComp.SR.tcActivePatternArgsCountNotMatchOnlyPat(caseName)|_,0-> FSComp.SR.tcActivePatternArgsCountNotMatchArgs(paramCount, fmtExprArgs paramCount, caseName)|_,_-> FSComp.SR.tcActivePatternArgsCountNotMatchArgsAndPat(paramCount, fmtExprArgs paramCount, caseName)giving etc. Or would that be overkill? What do you think @psfinaki? |
psfinaki
commented
Apr 24, 2024
In the topic of diagnostics, it's hard to do an overkill, it's more about perfectionism here now :) The current state of the art is definitely an improvement compared to the main. "Use 'IsEven' instead of 'IsEven x' probably captures most of the usecases and make the error very clear. The other errors importantly contain the expected number of "things" (arguments, expressions, patterns) and also list all these terms, like hey, there are all these capabilities of active patterns, read the docs if you're interested. So @Tangent-90 if you're not tired yet, feel free to use Brian's addition. If you are tired, feel free to leave things as they are. I'd just ask to add the tests for the new errors, among other things they can serve as documentation for the time being. |
message updated and test added @brianrourkeboll@psfinaki |
Uh oh!
There was an error while loading. Please reload this page.
psfinaki
left a comment
There was a problem hiding this comment.
Good stuff, thanks for this. Active patterns are much more usable now :)
Uh oh!
There was an error while loading. Please reload this page.
psfinaki
commented
May 2, 2024
Build errors are unrelated, we hope to resolve those soon, sorry. |


Description
Add a new error to improve readability for active pattern case argument count mismatch.
This active pattern case needs %d argument(s) and %d return value, but here has %d argument(s) and %d return value.QUESTION: what is the best name for the "return value" of an active pattern case?
before:
after:
Fixes # (issue, if applicable)
Checklist
Test cases added
Performance benchmarks added in case of performance changes
Release notes entry updated: