]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: avoid "not used" errors due to bad go/defer statements
authorRobert Griesemer <gri@golang.org>
Fri, 26 Aug 2022 03:32:27 +0000 (20:32 -0700)
committerRobert Griesemer <gri@google.com>
Thu, 1 Sep 2022 23:17:52 +0000 (23:17 +0000)
commit489f508ccfb7f0648852e0fea882b204a5776573
tree5d655587ab7821a00e741f311a4ed93456edeb76
parent330282a3a96099894ac0b6daceee19a483c12bbd
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>
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/types2/stmt.go
test/fixedbugs/issue23586.go