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

go/types: improve error message quality for ptr receiver errors (go/types differs from go tool compile) #36336

Open
gertcuykens opened this issue Dec 31, 2019 · 2 comments
Assignees
Milestone

Comments

@gertcuykens
Copy link
Contributor

@gertcuykens gertcuykens commented Dec 31, 2019

In this particular case go build has a vastly better error message, assuming it's not vscode but gopls who is responsible for altering the original compile message.

type roundTripper func(*http.Request) (*http.Response, error)

func (f roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { return f(req) }

func proxy(u url.URL) http.Handler {
	return httputil.ReverseProxy{
		Transport: roundTripper(func(req *http.Request) (*http.Response, error) {
			req.Header.Set("Host", u.Host)
			return http.DefaultTransport.RoundTrip(req)
		}),
		Director: func(req *http.Request) {
			req.URL.Scheme = u.Scheme
			req.URL.Host = u.Host
			req.Header.Set("Host", u.Host)
		},
	}
}

image

gopls:

cannot use (httputil.ReverseProxy literal) (value of type httputil.ReverseProxy) as http.Handler value in return statement: missing method ServeHTTP compiler

original go build compiler message:

cannot use httputil.ReverseProxy literal (type httputil.ReverseProxy) as type http.Handler in return argument:
        httputil.ReverseProxy does not implement http.Handler (ServeHTTP method has pointer receiver)
@gopherbot gopherbot added this to the Unreleased milestone Dec 31, 2019
@golang golang deleted a comment from gopherbot Jan 2, 2020
@muirdm

This comment has been minimized.

Copy link

@muirdm muirdm commented Jan 2, 2020

gopls uses the go/types package, not the compiler, to type check. go/types doesn't provide as useful of an error message in this situation. It can probably be improved but would be subject to the Go release cycle (rather than gopls).

/cc @griesemer

@stamblerre stamblerre modified the milestones: Unreleased, gopls unplanned Jan 2, 2020
@stamblerre stamblerre changed the title x/tools/gopls: does not implement x (x method has pointer receiver) x/tools/gopls: improve error message quality (go/types differs from go build) Jan 2, 2020
@griesemer griesemer changed the title x/tools/gopls: improve error message quality (go/types differs from go build) go/types: improve error message quality for ptr receiver errors (go/types differs from go tool compile) Jan 2, 2020
@griesemer griesemer self-assigned this Jan 2, 2020
@griesemer griesemer removed Tools gopls labels Jan 2, 2020
@griesemer griesemer modified the milestones: gopls unplanned, Go1.15 Jan 2, 2020
@griesemer

This comment has been minimized.

Copy link
Contributor

@griesemer griesemer commented Jan 2, 2020

This is a go/types, not a gopls issue. Stand-alone test case: https://play.golang.org/p/LAbt1say8h2

The compiler reports:
./prog.go:14:30: cannot use httputil.ReverseProxy literal (type httputil.ReverseProxy) as type http.Handler in return argument: httputil.ReverseProxy does not implement http.Handler (ServeHTTP method has pointer receiver)

go/types reports:
./prog.go:14:9: cannot use (httputil.ReverseProxy literal) (value of type httputil.ReverseProxy) as http.Handler value in return statement: missing method ServeHTTP

It should not be too hard to make the go/types error better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.