{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/10340","labels_url":"https://api.github.com/repos/golang/go/issues/10340/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/10340/comments","events_url":"https://api.github.com/repos/golang/go/issues/10340/events","html_url":"https://github.com/golang/go/issues/10340","id":66220512,"number":10340,"title":"spec: bounded types","user":{"login":"aubble","id":10180857,"avatar_url":"https://avatars.githubusercontent.com/u/10180857?v=3","gravatar_id":"","url":"https://api.github.com/users/aubble","html_url":"https://github.com/aubble","followers_url":"https://api.github.com/users/aubble/followers","following_url":"https://api.github.com/users/aubble/following{/other_user}","gists_url":"https://api.github.com/users/aubble/gists{/gist_id}","starred_url":"https://api.github.com/users/aubble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aubble/subscriptions","organizations_url":"https://api.github.com/users/aubble/orgs","repos_url":"https://api.github.com/users/aubble/repos","events_url":"https://api.github.com/users/aubble/events{/privacy}","received_events_url":"https://api.github.com/users/aubble/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-03T20:13:38Z","updated_at":"2015-04-03T21:58:55Z","closed_at":"2015-04-03T21:48:53Z","body":"\"The receiver is specified via an extra parameter section preceeding the method name. That parameter section must declare a single parameter, the receiver. Its type must be of the form T or *T (possibly using parentheses) where T is a type name. The type denoted by T is called the receiver base type; it must not be a pointer or interface type and it must be declared in the same package as the method. The method is said to be bound to the base type and the method name is visible only within selectors for that type.\" \r\n\r\n\"func (p *Point) Length() float64 {\r\nreturn math.Sqrt(p.x * p.x + p.y * p.y)\r\n}\r\n\r\nfunc (p *Point) Scale(factor float64) {\r\n\r\np.x *= factor\r\np.y *= factor\r\n}\r\nbind the methods Length and Scale, with receiver type *Point, to the base type Point.\"\r\n\r\n\r\nGolang spec says this for https://golang.org/ref/spec#Receiver I'm confused on that it says that the methods are bound to the Point type? Shouldn't it be binded to *Point and not Point? Because the method set of Point is only methods declared with receiver Point, not *Point and therefore it is bounded. Yes you can call the function with a variable of type Point and not *Point, but thats syntactical sugar no? Its not like its actually part of the methods spec of Point? Only *Point? So why is it \"bounded\" to Point? It also says this \"method name is visible only within selectors for that type.\" But for this its not, its only visible to *Point, not Point?"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/89432684","html_url":"https://github.com/golang/go/issues/10340#issuecomment-89432684","issue_url":"https://api.github.com/repos/golang/go/issues/10340","id":89432684,"user":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T21:58:55Z","updated_at":"2015-04-03T21:58:55Z","body":"It could perhaps say:\r\n\r\n... the method name is visible only within selectors _with_ that base type.\r\n\r\ni.e., if the type is a pointer type *T, its base type would be T. But it's all a slippery slope. There's always a balance between making the spec reasonably clear vs \"litigation-proof\". The latter it is not.\r\n"}}