-
Notifications
You must be signed in to change notification settings - Fork 397
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
fix(gnovm): Prevent use of blank identifier as Value or Type #2699
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Thanks Joon. Looks mostly good as it fixes the example in the issue. Can you also make a change that panics if the RHS identifier is _
during a DEFINE assignment? Maybe assert it is a named expression and compare its name to blankIdentifier
if it is.
package main
func main() {
a := _
}
And while you are making changes regarding the blank identifier, maybe we want to handle this case as well. It is technically a valid expression, though I can't think of a use case, so I'm not sure if we should fix it for any reason other than to more strictly adhere to the go spec.
package main
type zilch interface{}
func main() {
_ = zilch(nil)
}
It would be good to get @ltzmaxwell 's review on this as well.
@deelawn I've just finished up due to working on other tasks. Now I've modified the code based on your review. This cases seemed to require handling at the |
consider this one: package main
func main() {
var a = _
} |
there should be a better PR title too. |
@ltzmaxwell I apologize for the delay. I've made some changes to reflect your comments. Still, I can't think of a good idea for the PR title for now. Thanks! |
hey @notJoon, do you have time to take a look at the comments, so we can push this forward? thank you. |
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.
Ok to me
…#2699) # Description Closes gnolang#1946 The `isNamedConversion` function now includes a safety check to prevent the use of blank identifiers ("_") as values or types. If both `xt` and `t` are nil, the function assumes that a blank identifier is being used inappropriately and panics with an error message that includes the location of the issue. ## Variable Explanations - `xt` (Expression Type): Represents the type of the right-hand side of an assignment or expression. It's the type resulting from evaluating an expression. - `t` (Target Type): Represents the type of the left-hand side of an assignment. It's the variable or field that will receive the value. Checks if a named conversion is needed when assigning a value of type `xt` to a variable of type `t`. ## Preprocess Added some checks to prevent the disallowd usage of blank identifiers in `Preprocess` function level. Theses checks are performed at different stages of the preprocessing: 1. `TRANS_ENTER` for `AssignStmt`: - Checks if both LHS and RHS are blank identifiers in a `DEFINE` statement. 2. `TRANS_LEAVE` for `NameExpr`: - Checks if blank identifier is used as a value in disallowed contexts (excluding `TRANS_ASSIGN_LHS`, `TRANS_RANGE_KEY` and `TRANS_RANGE_VALUE`). 3. `TRANS_LEAVE` for `AssignStmt`: - Checks if RHS is a blank identifier when LHS is not, in a `DEFINE` statement. When any of these conditions are met, the function throws an panics like go message. <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [X] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [X] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
# Description Closes #1946 The `isNamedConversion` function now includes a safety check to prevent the use of blank identifiers ("_") as values or types. If both `xt` and `t` are nil, the function assumes that a blank identifier is being used inappropriately and panics with an error message that includes the location of the issue. ## Variable Explanations - `xt` (Expression Type): Represents the type of the right-hand side of an assignment or expression. It's the type resulting from evaluating an expression. - `t` (Target Type): Represents the type of the left-hand side of an assignment. It's the variable or field that will receive the value. Checks if a named conversion is needed when assigning a value of type `xt` to a variable of type `t`. ## Preprocess Added some checks to prevent the disallowd usage of blank identifiers in `Preprocess` function level. Theses checks are performed at different stages of the preprocessing: 1. `TRANS_ENTER` for `AssignStmt`: - Checks if both LHS and RHS are blank identifiers in a `DEFINE` statement. 2. `TRANS_LEAVE` for `NameExpr`: - Checks if blank identifier is used as a value in disallowed contexts (excluding `TRANS_ASSIGN_LHS`, `TRANS_RANGE_KEY` and `TRANS_RANGE_VALUE`). 3. `TRANS_LEAVE` for `AssignStmt`: - Checks if RHS is a blank identifier when LHS is not, in a `DEFINE` statement. When any of these conditions are met, the function throws an panics like go message. <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [X] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [X] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
Description
Closes #1946
The
isNamedConversion
function now includes a safety check to prevent the use of blank identifiers ("_") as values or types. If bothxt
andt
are nil, the function assumes that a blank identifier is being used inappropriately and panics with an error message that includes the location of the issue.Variable Explanations
xt
(Expression Type): Represents the type of the right-hand side of an assignment or expression. It's the type resulting from evaluating an expression.t
(Target Type): Represents the type of the left-hand side of an assignment. It's the variable or field that will receive the value.Checks if a named conversion is needed when assigning a value of type
xt
to a variable of typet
.Preprocess
Added some checks to prevent the disallowd usage of blank identifiers in
Preprocess
function level. Theses checks are performed at different stages of the preprocessing:TRANS_ENTER
forAssignStmt
:DEFINE
statement.TRANS_LEAVE
forNameExpr
:TRANS_ASSIGN_LHS
,TRANS_RANGE_KEY
andTRANS_RANGE_VALUE
).TRANS_LEAVE
forAssignStmt
:DEFINE
statement.When any of these conditions are met, the function throws an panics like go message.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description