Commit 52e9bcaf authored by Russ Cox's avatar Russ Cox

cmd/gc: print x++ (not x += 1) in errors about x++

Fixes #8311.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/146270043
parent 53c66543
...@@ -810,6 +810,13 @@ stmtfmt(Fmt *f, Node *n) ...@@ -810,6 +810,13 @@ stmtfmt(Fmt *f, Node *n)
break; break;
case OASOP: case OASOP:
if(n->implicit) {
if(n->etype == OADD)
fmtprint(f, "%N++", n->left);
else
fmtprint(f, "%N--", n->left);
break;
}
fmtprint(f, "%N %#O= %N", n->left, n->etype, n->right); fmtprint(f, "%N %#O= %N", n->left, n->etype, n->right);
break; break;
......
...@@ -460,11 +460,13 @@ simple_stmt: ...@@ -460,11 +460,13 @@ simple_stmt:
| expr LINC | expr LINC
{ {
$$ = nod(OASOP, $1, nodintconst(1)); $$ = nod(OASOP, $1, nodintconst(1));
$$->implicit = 1;
$$->etype = OADD; $$->etype = OADD;
} }
| expr LDEC | expr LDEC
{ {
$$ = nod(OASOP, $1, nodintconst(1)); $$ = nod(OASOP, $1, nodintconst(1));
$$->implicit = 1;
$$->etype = OSUB; $$->etype = OSUB;
} }
......
...@@ -600,6 +600,10 @@ reswitch: ...@@ -600,6 +600,10 @@ reswitch:
} }
if(t->etype != TIDEAL && !eqtype(l->type, r->type)) { if(t->etype != TIDEAL && !eqtype(l->type, r->type)) {
defaultlit2(&l, &r, 1); defaultlit2(&l, &r, 1);
if(n->op == OASOP && n->implicit) {
yyerror("invalid operation: %N (non-numeric type %T)", n, l->type);
goto error;
}
yyerror("invalid operation: %N (mismatched types %T and %T)", n, l->type, r->type); yyerror("invalid operation: %N (mismatched types %T and %T)", n, l->type, r->type);
goto error; goto error;
} }
......
This diff is collapsed.
// errorcheck
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// issue 8311.
// error for x++ should say x++ not x += 1
package p
func f() {
var x []byte
x++ // ERROR "invalid operation: x[+][+]"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment