-
Notifications
You must be signed in to change notification settings - Fork 803
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
"as" pattern with an identifier picks a literal #18315
Comments
Do you mean the F# 4.1 specification? Arbitrary patterns on the right-hand side of |
@brianrourkeboll Oh, thank you for the reference, I suppose I got failed there by the official documentation, 4.1 specification, and discord. I really wish there was a way to find out about this stuff without stumbling upon it by coincidence. Since the |
Yeah, there is a community effort under way to try to make it easier to keep the spec up to date: https://github.com/fsharp/fslang-spec?tab=readme-ov-file#overview
Right now, I believe it is in phase 2.
Yes, I think you are right that this was a breaking change. Note however that the compiler would have already emitted a warning for any identifier three characters or longer (#17878) starting with an uppercase letter in this position, which probably greatly limited any effect this might have had. (Edit: well, maybe it would have; maybe not, if identifiers in that position didn't go through the regular pattern typechecking. Either way, I guess we would probably have seen more noise in the last three years if it was really a widespread problem.) |
I think this RFC can be revised to reduce the scope of supported expressions on the righthand side of The described problem would however still remain if |
There has been a change in F# 6 that introduces arbitrary patterns to the right of
as
. However, this is also a breaking change in case an identifier is used that starts with an uppercase letter, which was an already valid syntax before F# 6 to create a new variable.Repro steps
Expected behavior
The match should succeed, bind
1
to a new variableCo
, and print "1".Actual behavior
"other" is printed, since it interprets the first pattern as
1 as 2
.Known workarounds
Not using identifiers after
as
that start on an uppercase letter.Related information
I am not sure if this behaviour is by design or not, since the RFC that introduces it does not discuss this case. However, I believe it is not by design, since the feature is marked as not being a breaking change. If the breaking change stays in, warnings should be issued since the interpretation of the code differs.
Environment: https://sharplab.io/#v2:DYLgZgzgPg2gPAGQJYBcCmAnAhsAfAXQFgAoYNFAAgGEB7CgXgoCYSBbLFAYwAsKBGCgHdU3ElH4UsEanQC0uCgAcMSAHYowFAER8tYigH0K8pSvWatNFN0xagA=
Trying this in an older version of the compiler exhibits the expected behaviour.
The text was updated successfully, but these errors were encountered: