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

bug: var declaration definition loop #1849

Closed
petar-dambovaliev opened this issue Mar 27, 2024 · 1 comment · Fixed by #1854 or #2074
Closed

bug: var declaration definition loop #1849

petar-dambovaliev opened this issue Mar 27, 2024 · 1 comment · Fixed by #1854 or #2074
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@petar-dambovaliev
Copy link
Contributor

petar-dambovaliev commented Mar 27, 2024

This code should print 1, 2 and 3. playground

package test

func main() {
	println(a)
	println(b)
	println(c)
}

var a, b, c = 1, a + 1, b + 1

Instead, it panics.

panic: constant definition loop with a [recovered]
	panic: test/main.go:2: constant definition loop with a [recovered]
	panic: test/main.go:2: constant definition loop with a

The fix for issue will possibly also implicate this bug.

A more complicated example that needs to work too

var a, b, c = 1, a + d, 3
var d = a

Here the initialization order needs to be a, d, b, c.
This means that the design of the implementation must be able to work in a more granular way.
This is a problem only for global var and const declarations.

@petar-dambovaliev petar-dambovaliev added 📦 🤖 gnovm Issues or PRs gnovm related 🐞 bug Something isn't working labels Mar 27, 2024
@petar-dambovaliev petar-dambovaliev self-assigned this Apr 4, 2024
petar-dambovaliev added a commit that referenced this issue Apr 9, 2024
This PR fixes [this](#1849) and
[this](#1463).

Before preprocessing, a dependency graph is created and edges between
the nodes which represent the relationship between global `var` and
`const` declarations.
Then, a new slice of declarations is created that is topologically
sorted.
This enables the rest of the preprocessing code to work the way it is
now.

Small scale refactoring is included by removing unnecessary else
statements in `PredefineFileSet`.
@petar-dambovaliev
Copy link
Contributor Author

After a conversation with @jaekwon , this should not be valid code in gno.

@Kouteki Kouteki moved this from Todo to In Progress in 🧙‍♂️gno.land core team May 15, 2024
thehowl added a commit that referenced this issue Sep 12, 2024
fixes [this](#1849) by splitting
value declarations with multiple values into single declarations with a
single value.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs

---------

Co-authored-by: Morgan Bazalgette <morgan@morganbaz.com>
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

Successfully merging a pull request may close this issue.

2 participants