969c3ba839
The primary change is that type inference now always reports an error if a unification step fails (rather than ignoring that case, see infer2.go). This brings the implementation closely to the description in #58650; but the implementation is more direct by always maintaining a simple (type parameter => type) mapping. To make this work, there are two small but subtle changes in the unifier: 1) When deciding whether to proceed with the underlying type of a defined type, we also use the underlying type if the other type is a basic type (switch from !hasName(x) to isTypeLit(x) in unifier.go). This makes the case in issue #53650 work out. See the comment in the code for a detailed explanation of this change. 2) When we unify against an unbound type parameter, we always proceed with its core type (if any). Again, see the comment in the code for a detailed explanation of this change. The remaining changes are comment and test adjustments. Because the new logic now results in failing type inference where it succeeded before or vice versa, and then instatiation or parameter passing failed, a handful of error messages changed. As desired, we still have the same number of errors for the same programs. Also, because type inference now produces different results, we cannot easily compare against infer1 anymore (also infer1 won't work correctly anymore due to the changes in the unifier). This comparison (together with infer1) is now disabled. Because some errors and their positions have changed, we need a slightly larger error position tolerance for types2 (which produces less accurate error positions than go/types). Hence the change in types2/check_test.go. Finally, because type inference is now slightly more relaxed, issue #51139 doesn't produce a type unification failure anymore for a (previously correctly) inferred type argument. Fixes #51139. Change-Id: Id796eea42f1b706a248843ad855d9d429d077bd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/470916 Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
go.env | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.