-
Notifications
You must be signed in to change notification settings - Fork 832
Allow simple arithmetic in number literals #14370
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
Conversation
|
@kerams Just to add another test case: please check it also works inside enum type definitions. |
|
Nice. Now the hardest part - an RFC :D. |
|
@auduchinok, no, that definitely won't work without parser changes. I'd prefer not to tackle that in this PR anyway (just because this is useful as it is, and easier to review). |
|
LGTM , provided tests are added. |
|
A shower thought - should this go under language flag? It technically changes compiler flow. |
|
@kerams if we can use |
|
@edgarfgp, I've tried let [<Literal>] switch2 =
match true with
| true -> true
| _ -> falseand it doesn't work.
|
|
@T-Gro @0101 @KevinRansom this is a non-breaking new language feature, however it changes compilation pipeline . Shall this be put under preview version, or we're fine enabling it for all versions? |
|
|
Yeah, it's just changing the codegen, not sure if someone can already rely on it in some tooling/when using quotations, etc. |
|
fsharp/src/Compiler/TypedTree/TypedTreeOps.fs Line 9667 in 23e22ea
One thing I'm not sure about is this comment. Edit: Oh, maybe since all the operations get erased and replaced by constants, that following phase does not have to be updated. |
|
Decimals are a no-go at the moment, because you can't even do |
|
Should also allow conversion operators between numeric types and |
|
Plenty of other things could theoretically be added - comparison and equality operators, even match expressions. However, I don't want to stray away from what has been proposed and approved too much, and make things unnecessarily complicated. |
|
I am for merging this in as-is without preview version restriction and letting others built on top of it with new ideas as needed in separate PRs. |
Why? It contradicts the whole point of having the language versions. It's not a bug fix, and new things can now be compiled that a previous language version didn't allow. |
Yep, was thinking the same, it changes the codegen and compilation pipeline. We should hide it behind preview version. |
I see it as an extension of a feature that was incomplete. That being said, it might be bad for developers having different SDK versions between each other (or between them and CI) while using an older F# language version. => you are right. |
|
Bump. Does it need Don's blessing? I have a working draft for expressions in enum definitions, but this PR is a requirement. |
I think we're fine with merging it |

Implements fsharp/fslang-suggestions#539.
RFC
+(unary and binary),-(unary and binary),*,/,%,&&&,|||,<<<,>>>are now allowed for integers in literals as well as attributes.not,&&,||are allowed for bools.