Skip to content

spec: disallow recursive embedded interfaces #1814

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

Closed
griesemer opened this issue May 12, 2011 · 10 comments
Closed

spec: disallow recursive embedded interfaces #1814

griesemer opened this issue May 12, 2011 · 10 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Milestone

Comments

@griesemer
Copy link
Contributor

The following declaration

type E interface {
    E
}

is accepted by neither the gc collection of compilers nor gccgo (interface type loop
involving E).

Arguably it is a legal declaration; at least there is no wording in the spec against it.

This is either a) a compiler bug, or b) the spec needs to be clearer. Also, this is a
completely academic issue with no practical implications...
@griesemer
Copy link
Contributor Author

Comment 1:

On a related subject, the spec does not say anything about struct types referring to
themselves directly or indirectly via field types (of named or anonymus fields).
With respect to the above example: While this special case may be easy to detect, more
complicated indirect scenarios are possible:
type E1 interface { E2 }
type E2 interface { E3 }
...
type En interface { E1 }
all of which are empty and thus theoretically legal. This will be harder to detect and
has no practical value. Such self-recursive interface types should not be allowed as per
current compiler implementation.
Changing this to a documentation issue: The spec should probably clarify what forms of
direct and indirect recursions are legal in type declarations.

Labels changed: added documentation, removed compilerbug, languagechange.

@griesemer
Copy link
Contributor Author

Comment 2:

Issue #1815 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented May 12, 2011

Comment 3:

I don't believe that
type E interface {
    E
}
is any more legal than
type T struct {
    T
}
In both cases there exists a minimal fixed point
that could in theory be arrived upon, but nothing
else in the language requires such analysis.
It's not just this specific case either.  I think the
interface embedding graph needs to be cycle free.
Russ

@griesemer
Copy link
Contributor Author

Comment 4:

I think we all agree.
- gri

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 6:

Labels changed: added priority-someday.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2011

Comment 7:

Labels changed: added priority-go1.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 8:

Owner changed to builder@golang.org.

@rsc
Copy link
Contributor

rsc commented Jan 30, 2012

Comment 10:

Labels changed: added go1-must.

@rsc
Copy link
Contributor

rsc commented Feb 8, 2012

Comment 11:

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Feb 8, 2012

Comment 12:

This issue was closed by revision 388816a.

Status changed to Fixed.

@griesemer griesemer added fixed Documentation Issues describing a change to documentation. labels Feb 8, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 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.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

4 participants