-
Notifications
You must be signed in to change notification settings - Fork 465
Add support for the bitwise NOT(~
) unary operator
#7418
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
~
) unary operator
rescript
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
@rescript/darwin-arm64
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! 🎉 Just left some comments.
@cristianoc could you review, too?
@@ -268,7 +268,7 @@ let rec go_to_closing closing_token state = | |||
(* Madness *) | |||
let is_es6_arrow_expression ~in_ternary p = | |||
Parser.lookahead p (fun state -> | |||
let async = | |||
let _async = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we didn't get a warning before if this is unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used for recovery on tilde token, I forgot to rollback the recovery change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not. we should remove the tilde handling because now we allow to use it somewhere in that context.
@@ -6,4 +6,7 @@ | |||
;;List.reduce (fun [arity:2]acc -> fun curr -> acc + curr) 0 myList | |||
let unitUncurried = apply () | |||
;;call ~a:(a : int) | |||
;;call (~ a) | |||
;;call ~a:(a ^ (~ a)) | |||
;;call ~a:(~ a) | |||
;;call_partial 3 ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some simple examples too? E.g. let z = ~y
. To illustrate where parens are added, and where they are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has been added in the unary.res
file already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Left a minor question.
@@ -315,7 +315,6 @@ let is_es6_arrow_expression ~in_ternary p = | |||
| EqualGreater -> true | |||
| _ -> false) | |||
| Dot (* uncurried *) -> true | |||
| Tilde when not async -> true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here where we use the async
bool value before
I'm merging this and continuing to work on the Let me know if there's still something that needs to be fixed |
Part of the #7172
Allows to use
~
in unary expressions, and make it as compiler primitive instead of using runtime library codeThere is one syntax ambiguity problem with function arguments as we already use tilde token for the labeled argument syntax, e.g.
So we decided to enforce parens on that case.
And also we add parens in binary expressions too:
Note: unlike existing
+
and-
,~n
is not being parsed as constant, only expression