cmd/compile: incorrect typecheck error for multiple assignment #43348
Comments
Go 1.11 is better:
gccgo says
|
The compiler with types2 reports:
I think this is about as good as the old error message. |
Change https://golang.org/cl/280112 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Dec 25, 2020
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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Narrator: f does not return 3 values.
Been this way back to Go 1.12 at least (I don't have earlier versions on my Mac laptop, and honestly I'm aamzed Go 1.12 still runs).
/cc @griesemer @mdempsky
The text was updated successfully, but these errors were encountered: