diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index e0129cf0e0..c6691851fb 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -346,7 +346,17 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { check.invalidAST(s.TokPos, "unknown inc/dec operation %s", s.Tok) return } + var x operand + check.expr(&x, s.X) + if x.mode == invalid { + return + } + if !isNumeric(x.typ) { + check.invalidOp(s.X.Pos(), "%s%s (non-numeric type %s)", s.X, s.Tok, x.typ) + return + } + Y := &ast.BasicLit{ValuePos: s.X.Pos(), Kind: token.INT, Value: "1"} // use x's position check.binary(&x, nil, s.X, Y, op) if x.mode == invalid { diff --git a/src/go/types/testdata/stmt0.src b/src/go/types/testdata/stmt0.src index b7966ed93d..fec16e1dd7 100644 --- a/src/go/types/testdata/stmt0.src +++ b/src/go/types/testdata/stmt0.src @@ -164,7 +164,7 @@ func incdecs() { const c = 3.14 c /* ERROR "cannot assign" */ ++ s := "foo" - s /* ERROR "cannot convert" */ -- + s /* ERROR "invalid operation" */ -- 3.14 /* ERROR "cannot assign" */ ++ var ( x int