]> Cypherpunks repositories - gostls13.git/commit
go/types: compute effective Go version independent of token.Pos
authorAlan Donovan <adonovan@google.com>
Mon, 16 Sep 2024 22:50:52 +0000 (18:50 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 26 Sep 2024 14:28:38 +0000 (14:28 +0000)
commit9b1f8f32b8b3ace71be1f77a6a500b1550365ec6
tree3f2168e1c028a75263b33e867a7ce53f51ce6fca
parent906338f82fc6641e834964def3199ac25df93e94
go/types: compute effective Go version independent of token.Pos

Previously, the Checker.allowVersion method would use a token.Pos
to try to infer which file of the current package the checker
was "in". This proved fragile when type-checking syntax that
had been modified or synthesized and whose positions were invalid.

This change records the effective version in the checker state
(checker.environment.version). Just like other aspects of the
environment, the version changes from one file to the next
and must be saved and restored with each check.later closure.

Similarly, declInfo captures and temporarily reinstates
the effective version when checking each object.

+ Test of position independence in go/types and types2
+ Test of panic avoidance in go/types

Fixes golang/go#69477
Fixes golang/go#69338

Change-Id: Ic06f9d88151c64a4f7848f8942d08e3c312cdd6f
Reviewed-on: https://go-review.googlesource.com/c/go/+/613735
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
30 files changed:
src/cmd/compile/internal/types2/api_predicates.go
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/conversions.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/literals.go
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/operand.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/version.go
src/go/types/api_predicates.go
src/go/types/api_test.go
src/go/types/call.go
src/go/types/check.go
src/go/types/conversions.go
src/go/types/decl.go
src/go/types/infer.go
src/go/types/instantiate.go
src/go/types/literals.go
src/go/types/lookup.go
src/go/types/operand.go
src/go/types/resolver.go
src/go/types/stmt.go
src/go/types/typeset.go
src/go/types/version.go