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/gotype: build tags not supported #23463

Open
benpaxton-hf opened this issue Jan 17, 2018 · 5 comments

Comments

@benpaxton-hf
Copy link

commented Jan 17, 2018

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Already using latest release, so yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOOS="linux"

What did you do?

Created a program where one of two build tags must be provided to build, then tried to lint it with gotype.

main.go

package main

import (
	"./sub"
	"fmt"
)

func main() {
	fmt.Printf("Hello, %s!\n", sub.Get())
}

sub/sub_a.go

//+build a

package sub

func Get() string {
	return "world"
}

sub/sub_b.go

//+build b

package sub

func Get() string {
	return "everyone"
}

sub/sub.go

package sub

// some shared code
$ ls
main.go  sub
$ gotype .
main.go:9:29: Get not declared by package sub
$ go run -tags a main.go 
Hello, world!
$ go run -tags b main.go 
Hello, everyone!

What did you expect to see?

gotype would have a -tags argument to specify build tags, e.g.

$ gotype -tags a .

What did you see instead?

gotype has no way to specify build tags for linting

@gopherbot gopherbot added this to the Unreleased milestone Jan 17, 2018

@cznic

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2018

I think there must be a space in // +build tag.

@benpaxton-hf

This comment has been minimized.

Copy link
Author

commented Jan 17, 2018

@cznic

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2018

Sorry, maybe I remember that from some older Go version.

@mvdan

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

This seems like a fine addition, but note that gotype isn't exactly a linter. All it does is type-check a program with go/types, which should generally be the same that you get when the compiler type-checks the same packages.

So perhaps it lacks some of these features on purpose, if it's meant to be more of a debugging tool. For example, it treats no arguments as using standard input, which is different from most static analysis tools.

/cc @griesemer

@griesemer griesemer self-assigned this Jan 17, 2018

@spf13 spf13 added the NeedsFix label Mar 26, 2018

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Mar 27, 2018

So, first of of all x/tools/cmd/gotype is an old version, left in x/tools because some people relied on it being there. The latest version is in the std library, under src/go/types, and must be built explicitly in that directory (go install gotypes.go).

Second, gotype was never meant to be a "lint" tool as you allude to, and as @mvdan also mentioned. It's a debugging tool for go/types, used to run go/types "stand-alone".

I'm going to change the title to refer to the latest version. We may fix this at some point, but it's certainly not urgent.

@griesemer griesemer changed the title x/tools/cmd/gotype: build tags not supported go/types/gotype: build tags not supported Mar 27, 2018

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