aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2022-08-25 20:32:27 -0700
committerRobert Griesemer <gri@google.com>2022-09-01 23:17:52 +0000
commit489f508ccfb7f0648852e0fea882b204a5776573 (patch)
tree5d655587ab7821a00e741f311a4ed93456edeb76 /src/cmd/compile/internal/syntax
parent330282a3a96099894ac0b6daceee19a483c12bbd (diff)
downloadgo-489f508ccfb7f0648852e0fea882b204a5776573.tar.xz
cmd/compile: avoid "not used" errors due to bad go/defer statements
The syntax for go and defer specifies an arbitrary expression, not a call; the call requirement is spelled out in prose. Don't to the call check in the parser; instead move it to the type checker. This is simpler and also allows the type checker to check expressions that are not calls, and avoid "not used" errors due to such expressions. We would like to make the same change in go/parser and go/types but the change requires Go/DeferStmt nodes to hold an ast.Expr rather than an *ast.CallExpr. We cannot change that for backward- compatibility reasons. Since we don't test this behavior for the type checkers alone (only for the compiler), we get away with it for now. Follow-up on CL 425675 which introduced the extra errors in the first place. Change-Id: I90890b3079d249bdeeb76d5673246ba44bec1a7b Reviewed-on: https://go-review.googlesource.com/c/go/+/425794 Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go14
1 files changed, 0 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index d86fe1b72e..8ba72fe7cf 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -953,20 +953,6 @@ func (p *parser) callStmt() *CallStmt {
x = t
}
- // TODO(gri) Now that we don't store a CallExpr in a CallStmt anymore
- // we might as well leave this check to the type checker.
- // Adjust this here and in go/parser eventually.
- if _, ok := x.(*CallExpr); !ok {
- // only report an error if it's a new one
- if bad, ok := x.(*BadExpr); !ok {
- p.errorAt(x.Pos(), fmt.Sprintf("expression in %s must be function call", s.Tok))
- // already progressed, no need to advance
- bad = new(BadExpr)
- bad.pos = x.Pos()
- x = bad
- }
- }
-
s.Call = x
return s
}