From: Robert Griesemer Date: Sat, 20 Aug 2022 02:01:05 +0000 (-0700) Subject: go/parser: match go/defer error message of syntax package X-Git-Tag: go1.20rc1~1411 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b9bf82465569397191a62c4e4fb9a7d1013a2e64;p=gostls13.git go/parser: match go/defer error message of syntax package Adjust corresponding type checker tests accordingly. For #54511. Change-Id: Ieaf29f26c0877973fc0acbde35292cd69a4b709c Reviewed-on: https://go-review.googlesource.com/c/go/+/425007 Auto-Submit: Robert Griesemer Reviewed-by: Alan Donovan Run-TryBot: Robert Griesemer Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index 2883ea1d3e..3ac350d8f8 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -1997,7 +1997,7 @@ func (p *parser) parseCallExpr(callType string) *ast.CallExpr { } if _, isBad := x.(*ast.BadExpr); !isBad { // only report error if it's a new one - p.error(p.safePos(x.End()), fmt.Sprintf("function must be invoked in %s statement", callType)) + p.error(p.safePos(x.End()), fmt.Sprintf("expression in %s must be function call", callType)) } return nil } diff --git a/src/go/parser/short_test.go b/src/go/parser/short_test.go index 88d93d67d6..86779e7e7e 100644 --- a/src/go/parser/short_test.go +++ b/src/go/parser/short_test.go @@ -170,8 +170,8 @@ var invalids = []string{ `package p; func f() { for x /* ERROR "boolean or range expression" */ := []string {} }`, `package p; func f() { for i /* ERROR "boolean or range expression" */ , x = []string {} }`, `package p; func f() { for i /* ERROR "boolean or range expression" */ , x := []string {} }`, - `package p; func f() { go f /* ERROR HERE "function must be invoked" */ }`, - `package p; func f() { defer func() {} /* ERROR HERE "function must be invoked" */ }`, + `package p; func f() { go f /* ERROR HERE "must be function call" */ }`, + `package p; func f() { defer func() {} /* ERROR HERE "must be function call" */ }`, `package p; func f() { go func() { func() { f(x func /* ERROR "missing ','" */ (){}) } } }`, `package p; func _() (type /* ERROR "found 'type'" */ T)(T)`, `package p; func (type /* ERROR "found 'type'" */ T)(T) _()`, diff --git a/src/go/types/testdata/check/stmt0.go b/src/go/types/testdata/check/stmt0.go index 0f164d36c8..b466ec8c60 100644 --- a/src/go/types/testdata/check/stmt0.go +++ b/src/go/types/testdata/check/stmt0.go @@ -229,7 +229,7 @@ func selects() { } func gos() { - go 1 /* ERROR HERE "function must be invoked" */ + go 1 /* ERROR HERE "must be function call" */ go int /* ERROR "go requires function call, not conversion" */ (0) go gos() var c chan int @@ -238,7 +238,7 @@ func gos() { } func defers() { - defer 1 /* ERROR HERE "function must be invoked" */ + defer 1 /* ERROR HERE "must be function call" */ defer int /* ERROR "defer requires function call, not conversion" */ (0) defer defers() var c chan int