Commit ef639b09 authored by Robert Griesemer's avatar Robert Griesemer

go/parser: permit parentheses in receiver types

Pending acceptance of CL 101500044
and adjustment of test/fixedbugs/bug299.go.

LGTM=adonovan
R=golang-codereviews, adonovan
CC=golang-codereviews
https://golang.org/cl/110160043
parent 89f185fe
...@@ -2310,9 +2310,9 @@ func (p *parser) parseReceiver(scope *ast.Scope) *ast.FieldList { ...@@ -2310,9 +2310,9 @@ func (p *parser) parseReceiver(scope *ast.Scope) *ast.FieldList {
return par return par
} }
// recv type must be of the form ["*"] identifier // recv type must be of the form ["*"] identifier, possibly using parentheses
recv := par.List[0] recv := par.List[0]
base := deref(recv.Type) base := unparen(deref(unparen(recv.Type)))
if _, isIdent := base.(*ast.Ident); !isIdent { if _, isIdent := base.(*ast.Ident); !isIdent {
if _, isBad := base.(*ast.BadExpr); !isBad { if _, isBad := base.(*ast.BadExpr); !isBad {
// only report error if it's a new one // only report error if it's a new one
......
...@@ -35,6 +35,9 @@ var valids = []string{ ...@@ -35,6 +35,9 @@ var valids = []string{
`package p; func f() { for _ = range "foo" + "bar" {} };`, `package p; func f() { for _ = range "foo" + "bar" {} };`,
`package p; func f() { var s []int; g(s[:], s[i:], s[:j], s[i:j], s[i:j:k], s[:j:k]) };`, `package p; func f() { var s []int; g(s[:], s[i:], s[:j], s[i:j], s[i:j:k], s[:j:k]) };`,
`package p; var ( _ = (struct {*T}).m; _ = (interface {T}).m )`, `package p; var ( _ = (struct {*T}).m; _ = (interface {T}).m )`,
`package p; func ((T),) m() {}`,
`package p; func ((*T),) m() {}`,
`package p; func (*(T),) m() {}`,
} }
func TestValid(t *testing.T) { func TestValid(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment