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

cmd/gc: improperly allows methods on non-local receivers if name already exists #5089

Closed
bradfitz opened this issue Mar 20, 2013 · 2 comments
Milestone

Comments

@bradfitz
Copy link
Contributor

gc lets this bad code compile:

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

package main

import "bufio"

func (r *bufio.Reader) Buffered() int { return -1 }

func main() {
}


If you change "Buffered" to some method that doesn't already exist, you get
the proper error message:

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

package main

import "bufio"

func (r *bufio.Reader) MonkeyPatch() int { return -1 }

func main() {
}

prog.go:5: cannot define new methods on non-local type bufio.Reader

gccgo doesn't have the problem.

Props to pabuhr for finding this (which led him to believe that Go does allow monkey
patching)
@DanielMorsing
Copy link
Contributor

Comment 1:

Fix at https://golang.org/cl/7767044/

@DanielMorsing
Copy link
Contributor

Comment 2:

This issue was closed by revision 7c3694c.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
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

4 participants