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

x/tools/go/packages: Package.Fset is nil when using NeedSyntax #48226

Open
gordonklaus opened this issue Sep 7, 2021 · 1 comment
Open

x/tools/go/packages: Package.Fset is nil when using NeedSyntax #48226

gordonklaus opened this issue Sep 7, 2021 · 1 comment

Comments

@gordonklaus
Copy link
Contributor

@gordonklaus gordonklaus commented Sep 7, 2021

What did you do?

package main

import (
	"fmt"
	"golang.org/x/tools/go/packages"
)

func main() {
	conf := &packages.Config{
		Mode: packages.NeedSyntax,
	}
	pkgs, err := packages.Load(conf, "fmt")
	if err != nil {
		panic(err)
	}
	fmt.Println(pkgs[0].Fset == nil)
}

What did you expect to see?

false

What did you see instead?

true

Rationale

This is apparently working as intended, as the documentation reads:

	// Fset provides position information for Types, TypesInfo, and Syntax.
	// It is set only when Types is set.
	Fset *token.FileSet

However, I see no reason why Fset should not be exposed when NeedSyntax is requested. In particular, Fset is needed for looking up position information for syntax elements.

@gopherbot gopherbot added the Tools label Sep 7, 2021
@gopherbot gopherbot added this to the Unreleased milestone Sep 7, 2021
@thanm
Copy link
Contributor

@thanm thanm commented Sep 7, 2021

@matloob per owners

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants