On Mon, Aug 7, 2017 at 9:23 PM Gert <gert.cuyk...@gmail.com> wrote:

> Can append or the compiler be made to prevent or warn for bugs like this?

No. Slice is a value and append accepts s not &s as its first argument.
That means the new slice value need be returned for code that uses the
resulting slice, which is the case most often seen.

> func main() {
> a := []byte("Help")
> b := append(a, []byte(" Me ")...)
> c := append(a, []byte(" Her")...)
> fmt.Println(string(a), "-", string(b), "-", string(c))
> }

Does this code really output what you want it to output?
https://play.golang.org/p/DWQXtkGByv

Assigning the result value of append to a different variable than its first
argument is completely valid, but one has to be really sure why to do that.
Did you mean https://play.golang.org/p/-OMw3qGYjU ?

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to