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/imports: Process does not handle nil src properly #19676

Closed
raphael opened this issue Mar 23, 2017 · 2 comments
Closed

x/tools/imports: Process does not handle nil src properly #19676

raphael opened this issue Mar 23, 2017 · 2 comments

Comments

@raphael
Copy link

raphael commented Mar 23, 2017

Go 1.8

The header comment of Process implies that the use of the src parameter is optional. However providing a nil value always results in the error:

expected 'package', found 'EOF'

This is because the value is a nil []byte but the go parser ParseFile function which is called internally expects src to be of type interface{}. This in turns causes readSource to return nil because the comparison with (interface{}) nil fails.

Either the header comment of Process should be updated or the code modified so that giving a nil src actually works (presumably the intended and better behavior). This requires tweaking the call to ParseFile to cast src to a nil interface{} if it's a nil []byte.

@gopherbot gopherbot added this to the Unreleased milestone Mar 23, 2017
@gopherbot
Copy link

CL https://golang.org/cl/38613 mentions this issue.

@haya14busa
Copy link
Contributor

replacing []byte(nil) to nil solves the problem but parse() expects non-nil src and we cannot support option.Fragment by this solution.

I fixed it by reading the data from filename before passing src to parse() function.
it's similar to src/cmd/gofmt.

@golang golang locked and limited conversation to collaborators Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants