aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/typecheck.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-23 16:14:59 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-12-25 09:18:20 +0000
commit396b6c2e7c5c368c67e71824471d4f2d48f5c128 (patch)
tree222c878df5c18a10dfe33a0538f313fb946592c8 /src/cmd/compile/internal/typecheck/typecheck.go
parente24d2f3d0513961441904afdf71cafe7808c0be9 (diff)
downloadgo-396b6c2e7c5c368c67e71824471d4f2d48f5c128.tar.gz
go-396b6c2e7c5c368c67e71824471d4f2d48f5c128.zip
[dev.regabi] cmd/compile: cleanup assignment typechecking
The assignment type-checking code previously bounced around a lot between the LHS and RHS sides of the assignment. But there's actually a very simple, consistent pattern to how to type check assignments: 1. Check the RHS expression. 2. If the LHS expression is an identifier that was declared in this statement and it doesn't have an explicit type, give it the RHS expression's default type. 3. Check the LHS expression. 4. Try assigning the RHS expression to the LHS expression, adding implicit conversions as needed. This CL implements this algorithm, and refactors tcAssign and tcAssignList to use a common implementation. It also fixes the error messages to consistently say just "1 variable" or "1 value", rather than occasionally "1 variables" or "1 values". Fixes #43348. Passes toolstash -cmp. Change-Id: I749cb8d6ccbc7d22cd7cb0a381f58a39fc2696b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/280112 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/typecheck.go')
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index 87daee123d..05a346b8c8 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -1690,6 +1690,11 @@ func checkassignlist(stmt ir.Node, l ir.Nodes) {
}
func checkassignto(src *types.Type, dst ir.Node) {
+ // TODO(mdempsky): Handle all untyped types correctly.
+ if src == types.UntypedBool && dst.Type().IsBoolean() {
+ return
+ }
+
if op, why := assignop(src, dst.Type()); op == ir.OXXX {
base.Errorf("cannot assign %v to %L in multiple assignment%s", src, dst, why)
return