Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/parser: relax receiver syntax #8493

Closed
rsc opened this issue Aug 7, 2014 · 2 comments
Closed

go/parser: relax receiver syntax #8493

rsc opened this issue Aug 7, 2014 · 2 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Aug 7, 2014

http://play.golang.org/p/ZNCKVEGTmv

package main

import "bufio"

func (x ***int) m() {}
func (x chan int) m() {}
func (x *bufio.Reader) m() {}

The compiler can print good errors for this (click compile):

prog.go:5: invalid receiver type ***int (**int is an unnamed type)
prog.go:6: invalid receiver type chan int (chan int is an unnamed type)
prog.go:7: cannot define new methods on non-local type bufio.Reader

go/parser rejects it early (click format):

/tmp/x.go:5:10: expected (unqualified) identifier
/tmp/x.go:6:9: expected (unqualified) identifier
/tmp/x.go:7:10: expected (unqualified) identifier

Since ast.FuncDecl.Recv is just a *FieldList, it seems like the parser can easily accept
and represent the input without changes to go/ast or go/printer, and then go/types (or a
compiler using go/parser) can do the semantic rejection of the receiver types at a
higher level and give better errors.
@gopherbot
Copy link

Comment 1:

CL https://golang.org/cl/123010044 mentions this issue.

@griesemer
Copy link
Contributor

Comment 2:

This issue was closed by revision a3c0ca5.

Status changed to Fixed.

@rsc rsc added fixed labels Aug 7, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
The ast and printer don't care, and go/types can provide
a better error message.

This change requires an update to the tests for go/types
(go.tools repo). CL forthcoming.

Fixes golang#8493.

LGTM=adonovan
R=rsc, adonovan
CC=golang-codereviews
https://golang.org/cl/123010044
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
The ast and printer don't care, and go/types can provide
a better error message.

This change requires an update to the tests for go/types
(go.tools repo). CL forthcoming.

Fixes golang#8493.

LGTM=adonovan
R=rsc, adonovan
CC=golang-codereviews
https://golang.org/cl/123010044
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants