diff options
author | Robert Griesemer <gri@golang.org> | 2021-03-17 22:13:16 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-03-23 05:11:09 +0000 |
commit | 8f19394b62a5b1651cd66eefb1bfeacc278966b9 (patch) | |
tree | af9e7e1c97239a9283eedd30c49f437e4acb054d /src/cmd/compile/internal/types2/api.go | |
parent | 0265b6475f08f2c23a742132db87c357fcbfa458 (diff) | |
download | go-8f19394b62a5b1651cd66eefb1bfeacc278966b9.tar.gz go-8f19394b62a5b1651cd66eefb1bfeacc278966b9.zip |
cmd/compile/internal/types2: refactor untyped conversions
Based on https://golang.org/cl/284256 for go/types.
Brings this code more in line with go/types.
Adjusted various tests to match new error messages which
generally are now better: for assignment errors, instead
of a generic "cannot convert" we now say "cannot use"
followed by a clearer reason as to why not.
Major differences to go/types with respect to the changed
files:
- Some of the new code now returns error codes, but they
are only used internally for now, and not reported with
errors.
- go/types does not "convert" untyped nil values to target
types, but here we do. This is unchanged from how types2
handled this before this CL.
Change-Id: If45336d7ee679ece100f6d9d9f291a6ea55004d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/302757
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/api.go')
-rw-r--r-- | src/cmd/compile/internal/types2/api.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go index 30f0430ff1..acb196a336 100644 --- a/src/cmd/compile/internal/types2/api.go +++ b/src/cmd/compile/internal/types2/api.go @@ -415,7 +415,8 @@ func AssertableTo(V *Interface, T Type) bool { // AssignableTo reports whether a value of type V is assignable to a variable of type T. func AssignableTo(V, T Type) bool { x := operand{mode: value, typ: V} - return x.assignableTo(nil, T, nil) // check not needed for non-constant x + ok, _ := x.assignableTo(nil, T, nil) // check not needed for non-constant x + return ok } // ConvertibleTo reports whether a value of type V is convertible to a value of type T. |