gno icon indicating copy to clipboard operation
gno copied to clipboard

fix: addressability

Open deelawn opened this issue 1 year ago • 6 comments

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: xxx message 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.

deelawn avatar Aug 27 '24 00:08 deelawn

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Aug 27 '24 00:08 codecov[bot]

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)
}

ltzmaxwell avatar Aug 29 '24 10:08 ltzmaxwell

another one out of scope too: 😆

package main

type MyInt int

func main() {

	_ = &MyInt
	_ = MyInt

}

ltzmaxwell avatar Aug 29 '24 11:08 ltzmaxwell

Nice catch. Fixed this one here: https://github.com/gnolang/gno/pull/2731/commits/69407141daef506c258b9087481ce195fb6678c2

deelawn avatar Aug 29 '24 22:08 deelawn

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.

deelawn avatar Aug 29 '24 23:08 deelawn

@ltzmaxwell to finish the work on this PR.

thehowl avatar Oct 21 '24 19:10 thehowl

Work on this will continue here https://github.com/gnolang/gno/pull/3198

petar-dambovaliev avatar Nov 26 '24 07:11 petar-dambovaliev

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.

github-actions[bot] avatar Feb 25 '25 02:02 github-actions[bot]

#3198 has been merged. Closing this PR.

thehowl avatar Feb 27 '25 10:02 thehowl