fix: addressability
Closes #2299.
This PR enforces addressability rules from the go spec. Basically, you can't take references of values that don't have addresses, which makes sense. I think it's important to have the VM's behavior match Go's in this regard. If this isn't in place before we launch and we decide to do it later, we run the risk of breaking realms with code that doesn't adhere to the addressability rules. Omitting addressability rules may also have unforeseen future consequences when we decide to make the VM compatible with newer Go language features.
Contributors' checklist...
- [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: xxxmessage was included in the description - [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to generated graphs, if any. More info here.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
:loudspeaker: Thoughts on this report? Let us know!
start looking, this seems to be a missing case:
package main
import "fmt"
type MyStruct struct {
Mp *int
}
func makeT() MyStruct {
x := 10
return MyStruct{Mp: &x}
}
func main() {
p := &makeT().Mp // This would cause an error because you cannot take the address of a struct field when the struct is a direct return value of a function.
fmt.Println(p)
}
another one out of scope too: 😆
package main
type MyInt int
func main() {
_ = &MyInt
_ = MyInt
}
Nice catch. Fixed this one here: https://github.com/gnolang/gno/pull/2731/commits/69407141daef506c258b9087481ce195fb6678c2
another one out of scope too: 😆
package main type MyInt int func main() { _ = &MyInt _ = MyInt }
Yeah, good catch but out of scope. But https://github.com/gnolang/gno/pull/2731/commits/3f4f1b6ee9c516cd7c3a79aa8e1ada304fd2639a ensures that when this is fixed that it won't be an addressability error message that is displayed.
@ltzmaxwell to finish the work on this PR.
Work on this will continue here https://github.com/gnolang/gno/pull/3198
This PR is stale because it has been open 3 months with no activity. Remove stale label or comment or this will be closed in 3 months.
#3198 has been merged. Closing this PR.