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

gochecksumtype: works only inside one package #4158

Open
5 tasks done
maratori opened this issue Oct 24, 2023 · 3 comments
Open
5 tasks done

gochecksumtype: works only inside one package #4158

maratori opened this issue Oct 24, 2023 · 3 comments
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@maratori
Copy link
Contributor

Welcome

Description of the problem

gochecksumtype doesn't report missing cases if the sum type is declared in one package and the type switch is in a different package (see #3671 (comment)).

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.55.0 built with go1.21.3 from de1c3919 on 2023-10-20T11:56:32Z

Configuration

# paste configuration file or CLI flags here

Go environment

$ go version && go env
go version go1.21.3 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/app/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2772357518=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

A minimal reproducible example or link to a public repository

/decl/decl.go

package decl

//sumtype:decl
type MySumType interface {
        sealed()
}

type VariantA struct{}

func (*VariantA) sealed() {}

type VariantB struct{}

func (*VariantB) sealed() {}

/usage/usage.go

package usage

import "decl"

func DoSomething(x decl.MySumType) {
        switch x.(type) { // <-- here is expected a report about missing VariantB
        case *decl.VariantA:
        }
}

Validation

  • Yes, I've included all information above (version, config, etc.).
@maratori maratori added the bug Something isn't working label Oct 24, 2023
@ldez ldez added the feedback required Requires additional feedback label Oct 24, 2023
@ldez
Copy link
Member

ldez commented Oct 24, 2023

Hello,

there is something missing in your report: Does the standalone linter has the same behavior?

After it's not unexpected based on how golangci-lint analyzes things.

@maratori
Copy link
Contributor Author

Does the standalone linter has the same behavior?

No, the standalone linter works well if you pass all packages to it (go-check-sumtype ./...).

@navijation
Copy link

Analysis drivers like golangci-lint may leverage the analysis framework's fact interface to avoid rerunning analysis on packages that are not either directly or indirectly modified since the last run. What this means is that an analyzer should:

  1. not strongly (caching might be fine for some drivers) rely on any kind of statefulness across packages, except for state exported using the facts API
  2. store all information that is required across packages and not available natively from Go's type system as facts

It looks like go-check-sumtype does not leverage facts at all. So it seems incompatible golangci-lint's caching mechanism unless rewritten appropriately such as in exhaustive.

@ldez ldez added dependencies Relates to an upstream dependency and removed feedback required Requires additional feedback labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants