-
Notifications
You must be signed in to change notification settings - Fork 790
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
Better diagnostics when using "as alias" in binding without wrapping expression in parens #5259
Comments
Yes, I've noticed that too a few times. But I heard somewhere that the syntax with parens in patterns is limited and somewhat special. It probably has to do with disambiguation, but I'm not sure. A related issue is that parens cannot be used to capture arguments for active patterns (weird, but true): #4828 |
This is likely due to disambiguation, so it could be by design. |
Ok, I'm starting to understand how the error message comes to be, it is taking This is still rather confusing, wondering if we can make it any better but it seems making it consistent either way would be a breaking change, so we need to figure out if something can be done with the error message. |
@isaacabraham this seems like a good candidate for tracking better error messages. The issue here is that we cannot disambiguate, but because the code is a valid alias for the whole pattern, we emit an error that may be misleading. |
This follows from the fact that A as B, C as D is equivalent to ((A as B), C) as D One way to avoid parentheses in the original example is to use let foo a b =
match a, b with
| Some _ & aa, None -> aa, None
| None, Some _ & bb -> None, bb As for a more helpful error message for the original example with I notice that the keyword description for fsharp/src/Compiler/FSComp.txt Line 1408 in fd642a9
Would it be worth updating "also used to give a name to a whole pattern within a pattern match" to point out that it has very low precedence and will thus bind everything to its left? |
@brianrourkeboll I still fumble on this error when using Maybe if there is a revisit of pattern matching to enable I think when I logged it, it was more of "principle of least surprise" approach (which is subjective / debatable) and confirming it is per the spec, more than being stuck with it, only experienced users commented here / no "newly adopting F#" users came here. "Wrap in parens" related issues and suggestions maybe should be tagged, considering there are compound adjustments to the parser that could be taken in consideration as a top level feature, and tackling few language suggestions at once. I don't feel it is important for this specific issue.
Adding note that it has low precedence, which can mandate disambiguation through wrapping the binding with parens (or something shorter, more english obviously) would make sense, I agree and this is an easy adjustment 🙂 Let see if there are good suggestion to complete the message on |
When giving alias via
as
, the first element of a tuple can be matched without wrapping it between parens, while the same doesn't work for any other items in the tuple.if I wrap the second tuple element in the match in parens, it compiles:
This seems to be inconsistent behaviour, failing principle of least surprise, and leading to confusing error message.
Is it according to spec or some issue that needs to be fixed? Should the parens be mandatory or optional in that case?
Reproduces in VS2015 and VS2017.
The text was updated successfully, but these errors were encountered: