What version of Go are you using (go version)?
1.20.1
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/bytedance/Library/Caches/go-build"
GOENV="/Users/bytedance/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bytedance/go/pkg/mod"
GONOPROXY="*.byted.org,*.everphoto.cn,git.smartisan.com"
GONOSUMDB="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOOS="darwin"
GOPATH="/Users/bytedance/go"
GOPRIVATE="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOPROXY="https://go-mod-proxy.byted.org,https://goproxy.cn,https://proxy.golang.org,direct"
GOROOT="/Users/bytedance/x/go/sdk/go1.20.1"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/Users/bytedance/x/go/sdk/go1.20.1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bytedance/x/go/sdk/go1.20.1/src/cmd/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b1/75_q2h8x6_zcbd_746_lvht40000gn/T/go-build2405814180=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
i write this code to explain:
package a
import _ "unsafe"
type A string
//go:linkname A.Fmt fmt.Sprintf
func (A) Fmt(a ...any) string
func main() {
println(A("%d").Fmt(1))
}
What did you expect to see?
at go1.19, i could run this program without compile error, the go:linkname works fine
What did you see instead?
./a.go:7:3: //go:linkname must refer to declared function or variable
and i print the context before the compile bad exit , i found the scope just contains funcdecl and typedecl, no type method decl
// cmd/compile/internal/noder/writer.go
switch obj := pw.curpkg.Scope().Lookup(l.local).(type) {
case *types2.Func, *types2.Var:
if _, ok := pw.linknames[obj]; !ok {
pw.linknames[obj] = l.remote
} else {
pw.errorf(l.pos, "duplicate //go:linkname for %s", l.local)
}
default:
// print here
for k,e := range pw.curpkg.Scope().Elems() {
println(1, k,e.String()) // just funcdecl and typedecl, no type method decl
}
if types.AllowsGoVersion(1, 18) {
pw.errorf(l.pos, "//go:linkname must refer to declared function or variable")
}
}
What version of Go are you using (
go version)?1.20.1
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env)?What did you do?
i write this code to explain:
What did you expect to see?
at go1.19, i could run this program without compile error, the
go:linknameworks fineWhat did you see instead?
and i print the context before the compile bad exit , i found the scope just contains funcdecl and typedecl, no type method decl