yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

Method reference to struct is altered when placed into a slice

Open SolarLune opened this issue 1 year ago • 0 comments

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.

SolarLune avatar Jan 05 '25 22:01 SolarLune