Skip to content
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

fakexml: doesn't terminate checking type X *X #1202

Closed
fho opened this issue Mar 16, 2022 · 3 comments
Closed

fakexml: doesn't terminate checking type X *X #1202

fho opened this issue Mar 16, 2022 · 3 comments
Labels

Comments

@fho
Copy link

@fho fho commented Mar 16, 2022

The following code causes staticcheck v0.2.2 (staticcheck ./...) to hang forever.
staticcheck v0.2.1 terminates quickly on the same code.

package main

import "fmt"

type OperationHeaders struct {
	OperationCode *OperationCode `xml:"operationCode"`
}

type OperationCode *OperationCode

func main() {
	fmt.Println("hello")
}

If the struct tag xml:"operationCode" in OperationHeaders is omitted, staticcheck 0.2.2 also terminates.

A type definition like this was generated by an xml code generator.
I don't know when such a type definition could make sense.
Go 1.17 and 1.18 compile the code without any issues.


$ staticcheck --version
staticcheck 2021.1.2 (v0.2.2)

$ staticcheck -debug.version
staticcheck 2021.1.2 (v0.2.2)

Compiled with Go version: go1.17.8
Main module:
	honnef.co/go/tools@v0.2.2 (sum: h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=)
Dependencies:
	github.com/BurntSushi/toml@v0.3.1 (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
	golang.org/x/mod@v0.3.0 (sum: h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=)
	golang.org/x/sys@v0.0.0-20210119212857-b64e53b001e4 (sum: h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=)
	golang.org/x/tools@v0.1.0 (sum: h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=)
	golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 (sum: h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=)
$ go version
go version go1.17.8 linux/amd64
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fho/.cache/go-build"
GOENV="/home/fho/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/fho/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fho/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/t/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build66536980=/tmp/go-build -gno-record-gcc-switches"
@fho fho added bug needs-triage Newly filed issue that needs triage labels Mar 16, 2022
@fho fho changed the title staticcheck hangs forever on recursive type definition staticcheck hangs forever on recursive type definition with buildtag Mar 16, 2022
@fho fho changed the title staticcheck hangs forever on recursive type definition with buildtag staticcheck hangs forever on recursive type definition with struct tag Mar 16, 2022
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Mar 16, 2022
@dominikh
Copy link
Owner

@dominikh dominikh commented Mar 16, 2022

Can reproduce.

@dominikh
Copy link
Owner

@dominikh dominikh commented Mar 16, 2022

In v0.2.2 we started reusing encoding/xml's logic for checking if types can be marshaled. We inherited its infinite loop (cf. https://go.dev/play/p/SYxLx7YKqoT which doesn't terminate).

This is (probably) fine for encoding/xml, which in general doesn't support cyclic data structures, but obviously not fine for static analysis.

@dominikh dominikh changed the title staticcheck hangs forever on recursive type definition with struct tag fakexml: doesn't terminate checking type X *X Mar 16, 2022
@fho
Copy link
Author

@fho fho commented Mar 31, 2022

thanks a lot @dominikh

dominikh added a commit that referenced this issue Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants