]> Cypherpunks.ru repositories - gostls13.git/commit
go/parser: report //go:build-derived Go version in ast.File.GoVersion
authorRuss Cox <rsc@golang.org>
Mon, 13 Mar 2023 21:35:03 +0000 (17:35 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 13 Apr 2023 18:39:29 +0000 (18:39 +0000)
commit92a3cb9ed14bce659540de8fef5e11fdb4973946
tree09c05ded0ac41226a5378e48b3d4506a785992e7
parent3de5b4da26b0062c9fd1b84849a0d4b7e78aaf5a
go/parser: report //go:build-derived Go version in ast.File.GoVersion

For #57001, compilers and others tools will need to understand that
a different Go version can be used in different files in a program,
according to the //go:build lines in those files.

Update go/parser to populate the new ast.File.GoVersion field.

This requires running the go/scanner in ParseComments mode
always and then implementing discarding of comments in the
parser instead of the scanner. The same work is done either way,
since the scanner was already preparing the comment result
and then looping. The loop has just moved into go/parser.

Also make the same changes to cmd/compile/internal/syntax,
both because they're necessary and to keep in sync with go/parser.

For #59033.

Change-Id: I7b867f5f9aaaccdca94af146b061d16d9a3fd07f
Reviewed-on: https://go-review.googlesource.com/c/go/+/476277
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/syntax/nodes.go
src/cmd/compile/internal/syntax/parser.go
src/go/build/deps_test.go
src/go/parser/parser.go
src/go/parser/parser_test.go
src/go/parser/testdata/goversion/t01.go [new file with mode: 0644]
src/go/parser/testdata/goversion/t02.go [new file with mode: 0644]
src/go/parser/testdata/goversion/t03.go [new file with mode: 0644]
src/go/parser/testdata/goversion/t04.go [new file with mode: 0644]
src/go/parser/testdata/goversion/t05.go [new file with mode: 0644]
src/go/parser/testdata/goversion/t06.go [new file with mode: 0644]