This might be a duplicate of #20859. Filing it separately because the discussion in #20859 is mostly about code-generation, not functional differences.
What version of Go are you using (go version)?
go version go1.8.1 darwin/amd64
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/aron/dev/rstudio/connect/_vendor:/Users/aron/dev/rstudio/connect"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ts/s940qvdj5vj1czr9qh07fvtw0000gn/T/go-build120790787=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
https://play.golang.org/p/Ig-Jnvz07B
package main
import (
"errors"
"fmt"
)
func ModifyErr(perr *error) {
*perr = errors.New("this err was modifed")
}
func Foo() (err error) {
err = errors.New("Foo error")
defer ModifyErr(&err)
return err
}
func Bar() error {
var err error
err = errors.New("Bar error")
defer ModifyErr(&err)
return err
}
func main() {
fmt.Printf("Foo: %s\n", Foo())
fmt.Printf("Bar: %s\n", Bar())
}
What did you expect to see?
The same behavior from both Foo and Bar; probably Bar is correct.
What did you see instead?
This code produces:
Foo: this err was modifed
Bar: Bar error
This might be a duplicate of #20859. Filing it separately because the discussion in #20859 is mostly about code-generation, not functional differences.
What version of Go are you using (
go version)?What operating system and processor architecture are you using (
go env)?What did you do?
https://play.golang.org/p/Ig-Jnvz07B
What did you expect to see?
The same behavior from both
FooandBar; probablyBaris correct.What did you see instead?
This code produces: