Skip to content
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

blank identifier "_" should not be used as value or type #1946

Closed
ltzmaxwell opened this issue Apr 18, 2024 · 0 comments · Fixed by #2699
Closed

blank identifier "_" should not be used as value or type #1946

ltzmaxwell opened this issue Apr 18, 2024 · 0 comments · Fixed by #2699
Assignees
Labels
🐞 bug Something isn't working

Comments

@ltzmaxwell
Copy link
Contributor

this should fail in Gno but not:

package main

func main() {

	_ = _
}
@Kouteki Kouteki moved this from Triage to Backlog in 🧙‍♂️gno.land core team Apr 26, 2024
@zivkovicmilos zivkovicmilos added 🐞 bug Something isn't working 🌟 must have 🌟 labels Sep 11, 2024
@Kouteki Kouteki added this to the 🚀 Mainnet launch milestone Oct 16, 2024
@Kouteki Kouteki moved this from Backlog to In Progress in 🧙‍♂️gno.land core team Oct 21, 2024
ltzmaxwell pushed a commit that referenced this issue Nov 27, 2024
# 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 <morgan@morganbaz.com>
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team Nov 27, 2024
r3v4s pushed a commit to gnoswap-labs/gno that referenced this issue Dec 10, 2024
…#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 <morgan@morganbaz.com>
albttx pushed a commit that referenced this issue Jan 10, 2025
# 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 <morgan@morganbaz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Status: Done
Status: Onbloc (confirmed)
Development

Successfully merging a pull request may close this issue.

4 participants