diff options
author | Robert Griesemer <gri@golang.org> | 2022-04-20 12:05:30 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-04-20 20:49:36 +0000 |
commit | e49b80a754c3df1a82d089a16a46ea8946d5a00b (patch) | |
tree | bcea422762f57b800d16a1a65755c21807570320 | |
parent | c75befeec2a8ef2fea3c41da589ca0ffddda506f (diff) | |
download | go-e49b80a754c3df1a82d089a16a46ea8946d5a00b.tar.gz go-e49b80a754c3df1a82d089a16a46ea8946d5a00b.zip |
cmd/compile/internal/syntax: correct an error string
When we have an error in a function type used in an expression
we don't know until we see an opening { whether we have a function
literal or a function type. Use "function type" as context because
that's always correct in the specific error message.
Change-Id: I9aad8fcddf31ae53daa53cebd2c2001f08eabde0
Reviewed-on: https://go-review.googlesource.com/c/go/+/401316
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
-rw-r--r-- | src/cmd/compile/internal/syntax/parser.go | 2 | ||||
-rw-r--r-- | src/cmd/compile/internal/syntax/testdata/issue48382.go | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index 9de6d4f45eb..fe1c76e81b8 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -991,7 +991,7 @@ func (p *parser) operand(keep_parens bool) Expr { case _Func: pos := p.pos() p.next() - _, ftyp := p.funcType("function literal") + _, ftyp := p.funcType("function type") if p.tok == _Lbrace { p.xnest++ diff --git a/src/cmd/compile/internal/syntax/testdata/issue48382.go b/src/cmd/compile/internal/syntax/testdata/issue48382.go index c00fee6f826..7c024a051f6 100644 --- a/src/cmd/compile/internal/syntax/testdata/issue48382.go +++ b/src/cmd/compile/internal/syntax/testdata/issue48382.go @@ -8,7 +8,8 @@ type _ func /* ERROR function type must have no type parameters */ [ /* ERROR em type _ func /* ERROR function type must have no type parameters */ [ x /* ERROR missing type constraint */ ]() type _ func /* ERROR function type must have no type parameters */ [P any]() -var _ = func /* ERROR function literal must have no type parameters */ [P any]() {} +var _ = (func /* ERROR function type must have no type parameters */ [P any]())(nil) +var _ = func /* ERROR function type must have no type parameters */ [P any]() {} type _ interface{ m /* ERROR interface method must have no type parameters */ [P any]() |