]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: introduce _Alias type node
authorRobert Griesemer <gri@golang.org>
Tue, 22 Aug 2023 21:53:57 +0000 (14:53 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 9 Nov 2023 17:24:42 +0000 (17:24 +0000)
commitbea55136b2d50fc514ddfba4380311295975a660
treeedc6d9d139d337afaaf5a51483a5261d6e2946a2
parent1b03ec8a25412342ca072c0860bdf046d58e82ac
go/types, types2: introduce _Alias type node

This change introduces a new (unexported for now) _Alias type node
which serves as an explicit representation for alias types in type
alias declarations:

        type A = T

The _Alias node stands for the type A in this declaration, with
the _Alias' actual type pointing to (the type node for) T.
Without the _Alias node, (the object for) A points directly to T.

Explicit _Alias nodes permit better error messages (they mention
A instead of T if the type in the source was named A) and can help
with certain type cycle problems. They are also needed to hold
type parameters for alias types, eventually.

Because an _Alias node is simply an alternative representation for
an aliased type, code that makes type-specific choices must always
look at the actual (unaliased) type denoted by a type alias.
The new function

        func _Unalias(t Type) Type

performs the necessary indirection. Type switches that consider
type nodes, must either switch on _Unalias(typ) or handle the
_Alias case.

To avoid breaking clients, _Alias nodes must be enabled explicitly,
through the new Config flag _EnableAlias.

To run tests with the _EnableAlias set, use the new -alias flag as
in "go test -run short -alias". The testing harness understands
the flag as well and it may be used to enable/disable _Alias nodes
on a per-file basis, with a comment ("// -alias" or // -alias=false)
on the first line in those files. The file-based flag overrides the
command-line flag.

The use of _Alias nodes is disabled by default and must be enabled
by setting _EnableAlias.

Passes type checker tests with and without -alias flag set.

For #25838.
For #44410.
For #46477.

Change-Id: I78e178a1aef4d7f325088c0c6cbae4cfb1e5fb5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/521956
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
50 files changed:
src/cmd/compile/internal/types2/alias.go
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/interface.go
src/cmd/compile/internal/types2/issues_test.go
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/mono.go
src/cmd/compile/internal/types2/named.go
src/cmd/compile/internal/types2/object.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/signature.go
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/typexpr.go
src/cmd/compile/internal/types2/unify.go
src/cmd/compile/internal/types2/validtype.go
src/go/types/alias.go
src/go/types/api.go
src/go/types/check.go
src/go/types/check_test.go
src/go/types/decl.go
src/go/types/infer.go
src/go/types/interface.go
src/go/types/issues_test.go
src/go/types/lookup.go
src/go/types/mono.go
src/go/types/named.go
src/go/types/object.go
src/go/types/predicates.go
src/go/types/resolver.go
src/go/types/signature.go
src/go/types/typestring.go
src/go/types/typexpr.go
src/go/types/unify.go
src/go/types/validtype.go
src/internal/types/testdata/check/cycles5.go
src/internal/types/testdata/check/cycles5a.go [new file with mode: 0644]
src/internal/types/testdata/check/decls4.go
src/internal/types/testdata/check/issues0.go
src/internal/types/testdata/fixedbugs/issue25838.go
src/internal/types/testdata/fixedbugs/issue28251.go
src/internal/types/testdata/fixedbugs/issue46461.go
src/internal/types/testdata/fixedbugs/issue46461a.go [new file with mode: 0644]
src/internal/types/testdata/fixedbugs/issue47968.go
src/internal/types/testdata/fixedbugs/issue50779.go
src/internal/types/testdata/fixedbugs/issue50779a.go [new file with mode: 0644]
src/internal/types/testdata/spec/assignability.go