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

proposal: go/parser: deprecate parser.ParseDir (which returns deprecated type ast.Package) #71122

Open
soerenkoehler opened this issue Jan 4, 2025 · 2 comments
Labels
Milestone

Comments

@soerenkoehler
Copy link

soerenkoehler commented Jan 4, 2025

Go version

1.23.4

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/soeren/.cache/go-build'
GOENV='/home/soeren/.config/go/env'
GOEXE=''
GOEXPERIMENT='nocoverageredesign'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/soeren/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/soeren/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/opt/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/soeren/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/soeren/usrdev/go-util-mutation/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-build2925151345=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Write some simple code using the go/ast and go/parser:

func createAST() {
	ast := map[string]*ast.Package{}
	fset := token.NewFileSet()
	chain := &util.ChainContext{}

	chain.Chain(func() {
		ast, chain.Err = parser.ParseDir(fset, ".", nil, 0)
	}).Chain(func() {
		chain.Err = format.Node(os.Stdout, fset, ast)
	}).ChainFatal("Error")
}

What did you see happen?

The IDE marks ast.Package as deprecated conforming to the comment on the type. But parser.ParseDir() nevertheless references ast.Package in its return type.

What did you expect to see?

Either:

  • Having deprecated types consistently replaced in the stdlib. Thus, let ParseDir() use the recommended replacement type.

Or:

  • Having ParseDir() marked as deprecated too.
@mateusz834 mateusz834 changed the title [consistency] type ast.Package is deprecated but nevertheless used by parser.ParseDir() go/parser: type ast.Package is deprecated but nevertheless used by parser.ParseDir() Jan 4, 2025
@gabyhelp
Copy link

gabyhelp commented Jan 4, 2025

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@adonovan
Copy link
Member

adonovan commented Jan 4, 2025

What did you expect to see?
Either: Having deprecated types consistently replaced in the stdlib. Thus, let ParseDir() use the recommended replacement type.

ParseDir cannot be compatibly changed to return the recommended replacement type.

Or: Having ParseDir() marked as deprecated to.

I think parser.ParseDir is almost never the best solution to a problem, and it returns deprecated data structures, so it does make sense to deprecate it. A more robust solution is to use packages.Load, which invokes go list (or the appropriate build metadata query tool) to get the correct answer.

@adonovan adonovan changed the title go/parser: type ast.Package is deprecated but nevertheless used by parser.ParseDir() go/parser: deprecate parser.ParseDir (which returns deprecated type ast.Package) Jan 4, 2025
@adonovan adonovan changed the title go/parser: deprecate parser.ParseDir (which returns deprecated type ast.Package) proposal: go/parser: deprecate parser.ParseDir (which returns deprecated type ast.Package) Jan 4, 2025
@gopherbot gopherbot added this to the Proposal milestone Jan 4, 2025
@adonovan adonovan moved this to Incoming in Proposals Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants