The ParseDir function in "go/parser" does not respect the "+build 1.9" constraint in the comment and tries to parse the file anyways causing it to throw an error.
What did you expect to see?
I expected the ParseDir to ignore the file as the file has an Build Constraint which should signal ParseDir which is trying to parse all *.go" files for their AST that it cannot fully parse this file.
What did you see instead?
The ParseDir throws a mysterious error:
src/golang.org/x/net/context pkg cause error: src/golang.org/x/net/context/go19.go:15:14: expected type, found '=' (and 1 more errors)
The text was updated successfully, but these errors were encountered:
go/parser.ParseDir does not and by design must not consider build tags.
If you need to discriminate by build constraints you can use the PackageClauseOnly|ParseComments mode to handle them by yourself or you can use go/build.ImportDir.
umarniz
added a commit
to umarniz/swagger
that referenced
this issue
Jul 25, 2017
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Atleast go 1.7 & 1.8 have this error
What operating system and processor architecture are you using (
go env
)?Can reproduce this error on Mac & Linux
What did you do?
I can build my program fine even if there is a file that is only supposed to compile with go 1.9 with a build constraint for example:
https://github.com/golang/net/blob/master/context/go19.go
The ParseDir function in "go/parser" does not respect the "+build 1.9" constraint in the comment and tries to parse the file anyways causing it to throw an error.
What did you expect to see?
I expected the ParseDir to ignore the file as the file has an Build Constraint which should signal ParseDir which is trying to parse all *.go" files for their AST that it cannot fully parse this file.
What did you see instead?
The ParseDir throws a mysterious error:
The text was updated successfully, but these errors were encountered: