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)
break;
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);
break;
......
......@@ -460,11 +460,13 @@ simple_stmt:
| expr LINC
{
$$ = nod(OASOP, $1, nodintconst(1));
$$->implicit = 1;
$$->etype = OADD;
}
| expr LDEC
{
$$ = nod(OASOP, $1, nodintconst(1));
$$->implicit = 1;
$$->etype = OSUB;
}
......
......@@ -600,6 +600,10 @@ reswitch:
}
if(t->etype != TIDEAL && !eqtype(l->type, r->type)) {
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);
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