gopy icon indicating copy to clipboard operation
gopy copied to clipboard

Compile error when a function parameter name is same with package name

Open SuperScript-PRC opened this issue 4 months ago • 0 comments

See example:

package packet

func GoPacketToBytes(shieldID int, packet Packet) ([]byte, error) { // gopy bug
	buf := bytes.NewBuffer([]byte{})
	w := protocol.NewWriter(buf, int32(shieldID))
	packet.Marshal(w)
	return buf.Bytes(), nil
}

Use gopy build it will generate Go file which includes:

        packet.GoPacketToBytes( ... )

which causes compile problem. Rename parameter packet could solve it, but it's better to fix this problem since the error log is weird to greenhands.

SuperScript-PRC avatar Oct 08 '25 17:10 SuperScript-PRC