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

spec: document interface satisfaction more explicitly #5570

Closed
dsymonds opened this issue May 28, 2013 · 13 comments
Closed

spec: document interface satisfaction more explicitly #5570

dsymonds opened this issue May 28, 2013 · 13 comments

Comments

@dsymonds
Copy link
Contributor

http://golang.org/ref/spec#Interface_types does not clearly spell out the requirements
for a type to implement an interface. It should.
@cznic
Copy link
Contributor

cznic commented May 28, 2013

Comment 1:

IMO, the first three sentences at the link do define both exactly and completely
(together -> clearly) the requirements:
"""
An interface type specifies a method set called its interface. A variable of interface
type can store a value of any type with a method set that is any superset of the
interface. Such a type is said to implement the interface. 
"""

@dsymonds
Copy link
Contributor Author

Comment 2:

It does not define the set inclusion criteria. One might (incorrectly)
guess assignability or callability. Or might guess that parameter names
must match too.

@DanielMorsing
Copy link
Contributor

Comment 3:

The section on method sets describes that the inclusion criteria is only related to
methods, but doesn't say what it is exactly.
The compilers use the rules for function identity for interface matching. You could
probably refer to the type identity section, but extending it to methods or members of
method sets might be confusing. Methods don't exist as types in the language, and
methods and members of method sets have different identity rules.
Example:
method identity:
func (f Foo) Bar(fb FooBar) == func (b Foo) Bar(bf FooBar)
func (f Foo) Bar(fb FooBar) != func (b FooBar) Bar(bf Foo)
member of method set identity:
func (f Foo) Bar(fb FooBar) == func (b FooBar) Bar(bf FooBar)

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 4:

Labels changed: added go1.2.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 6:

Labels changed: added go1.2maybe, removed go1.2.

@rsc
Copy link
Contributor

rsc commented Nov 25, 2013

Comment 7:

Labels changed: added go1.3, removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 8:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 9:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 10:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented May 27, 2014

Comment 11:

Labels changed: added release-go1.4, removed release-go1.3.

@rsc
Copy link
Contributor

rsc commented Oct 28, 2014

Comment 12:

Labels changed: added release-go1.4maybe, removed release-go1.4.

@rsc
Copy link
Contributor

rsc commented Nov 6, 2014

Comment 13:

Labels changed: added release-go1.5, removed release-go1.4maybe.

@griesemer
Copy link
Contributor

The Go 1.18 spec has now a section on what it means to implement an interface (see the end of the section on Interface types). Closing.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
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

7 participants