New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/vet: stdmethods check gets confused if run on a package named "xml" #29750

Open
jacoelho opened this Issue Jan 15, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@jacoelho
Copy link

jacoelho commented Jan 15, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jc/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jc/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pf/_mdvc42j193c4tf6kgfm80gcss_jqd/T/go-build565539251=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

For example, if I have the following package:

package xml

import (
	"encoding/xml"
	"io"
)

type XMLMap map[string]string

type XMLMapEntry struct {
	XMLName xml.Name
	Value   string `xml:",chardata"`
}

// UnmarshalXML 
func (m *XMLMap) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	v := XMLMap{}

	for {
		var e XMLMapEntry

		err := dec.Decode(&e)
		if err == io.EOF {
			break
		}

		if err != nil {
			return err
		}

		v[e.XMLName.Local] = e.Value
	}

	*m = v
	return nil
}

What did you expect to see?

go vet ./...
< no output>

What did you see instead?

$ go vet ./...
./xml.go:16: method UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error should have signature UnmarshalXML(*xml.Decoder, xml.StartElement) error

even if I try to alias encoding/xml import I still get same error.

If instead I have the same code, but rename package:

package something
...
<same code as before>
go vet ./...
< no output>

go vet doesn't seem to handle correctly if code is in package also named xml.

@mvdan

This comment has been minimized.

Copy link
Member

mvdan commented Jan 15, 2019

Interesting. Like you say, this sounds like a bug in vet relating to how it identifies or compares types.

@mvdan mvdan added the NeedsFix label Jan 15, 2019

@mvdan mvdan changed the title cmd/vet: xml.Marshaler/Unmarshaler check cmd/vet: stdmethods check gets confused if run on a package named "xml" Jan 15, 2019

@mvdan mvdan added this to the Go1.13 milestone Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment