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

Method reference to struct is altered when placed into a slice #1675

Open
SolarLune opened this issue Jan 5, 2025 · 0 comments
Open

Method reference to struct is altered when placed into a slice #1675

SolarLune opened this issue Jan 5, 2025 · 0 comments

Comments

@SolarLune
Copy link

The following program sample.go triggers an unexpected result

package main

import "fmt"

type basic struct{}

func (b *basic) Run() {
	test := []any{b}          // Placing the reference to the struct in a slice "changes" it somehow
	fmt.Println(test[0] == b) // Should be true, is false instead
	fmt.Println(b, test[0]) // Both objects printed should be identical; they are on Go, and aren't on Yaegi
}

func main() {
	b := &basic{}
	b.Run()
}

Expected result

true
&{} &{}

Got

false
&{} {0xc0004d5a40 {0xc000409b40 0xc000448788 406}}

Yaegi Version

devel

Additional Notes

Hello, I stumbled on this when checking equality to a struct pointer I placed in a slice; for whatever reason, the pointer is modified when placed into the slice, such that its reference no longer equates to itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant