]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: don't do version checks for embedded types of imported interfaces
authorRobert Griesemer <gri@golang.org>
Tue, 12 Mar 2024 16:31:06 +0000 (09:31 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 14 Mar 2024 23:12:40 +0000 (23:12 +0000)
commit133c8fc9bb0f5f9a16a0756ba61990cae1e64008
treeae4f14318e8afffea5a4e937bfc1d6786d1311ea
parent412623c53fbb1b3ff29035022ef70374db35e826
go/types, types2: don't do version checks for embedded types of imported interfaces

This is a cherry-pick of CL 571075 combined with adjustments for 1.23:

Imported interfaces don't have position information for embedded types.
When computing the type set of such interfaces, doing a version check
may fail because it will rely on the Go version of the current package.

We must not do a version check for features of types from imported
packages - those types have already been typechecked and are "correct".
The version check code does look at packages to avoid such incorrect
version checks, but we don't have the package information available
in an interface type (divorced from its object).

Instead, rely on the fact that imported interfaces don't have position
information for embedded types: if the position is unknown, don't do a
version check.

In Checker.allowVersion, still allow for unknown positions and resort
to the module version in that case (source code may be generated by
tools and not contain position information). Also, remove the *Package
argument as it was always check.pkg except in one case, and that case
may in fact be incorrect; treat that case separately for now.

Fixes #66064.

Change-Id: I773d57e5410c3d4a911ab3e018b3233c2972b3c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/571075
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/571137
20 files changed:
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/expr.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/instantiate.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/call.go
src/go/types/check.go
src/go/types/conversions.go
src/go/types/expr.go
src/go/types/generate_test.go
src/go/types/infer.go
src/go/types/instantiate.go
src/go/types/stmt.go
src/go/types/typeset.go
src/go/types/version.go
src/internal/types/testdata/fixedbugs/issue66064.go [new file with mode: 0644]