// which turns an expression into an assignment. Provide
// a more explicit error message in that case to prevent
// further confusion.
- str := String(s)
+ var str string
if as, ok := s.(*AssignStmt); ok && as.Op == 0 {
- str = "assignment " + str
+ // Emphasize Lhs and Rhs of assignment with parentheses to highlight '='.
+ // Do it always - it's not worth going through the trouble of doing it
+ // only for "complex" left and right sides.
+ str = "assignment (" + String(as.Lhs) + ") = (" + String(as.Rhs) + ")"
+ } else {
+ str = String(s)
}
- p.syntaxError(fmt.Sprintf("%s used as value", str))
+ p.syntaxErrorAt(s.Pos(), fmt.Sprintf("cannot use %s as value", str))
}
p.xnest = outer
package p
func _() {
- if a := 10 { // ERROR "a := 10 used as value"
+ if a := 10 { // ERROR "cannot use a := 10 as value"
}
- for b := 10 { // ERROR "b := 10 used as value"
+ for b := 10 { // ERROR "cannot use b := 10 as value"
}
- switch c := 10 { // ERROR "c := 10 used as value"
+ switch c := 10 { // ERROR "cannot use c := 10 as value"
}
}