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: initialization cycle not detected #6683

Closed
griesemer opened this issue Oct 29, 2013 · 4 comments
Closed

cmd/gc: initialization cycle not detected #6683

griesemer opened this issue Oct 29, 2013 · 4 comments
Milestone

Comments

@griesemer
Copy link
Contributor

The following program correctly reports an initialization cycle:

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

Adding an interface type to line 7 (but leaving everything else unchanged) does not
report a cycle anymore:

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

The spec is vague/incomplete with respect to cycles involving methods, but if a cycle
can be detected in the first case, it should be detectable in the 2nd case. The program
is self-contained and erroneous.
@griesemer
Copy link
Contributor Author

Comment 1:

gccgo has the same bug (issue #6684).

@griesemer
Copy link
Contributor Author

Comment 2:

Arguably, this is _not_ a compiler error as in general such cases cannot be detected
without more sophisticated data flow analysis. For instance, the same situation appears
in:
package p
type T struct{}
func (T) m() int { return y }
var y = f()
func f() int {
    var x interface {
        m() int
    } = T{}
    return x.m()
}
where we have a cycle but the compiler doesn't detect it. Again, in this specific case
it could, but in general, the (conservative set of) dynamic type of x inside f may not
be computable w/o some form of data flow analysis, which we are explicitly not requiring.
Thus, perhaps simply the spec needs to be clarified here (what to do when methods are
invoked).

@griesemer
Copy link
Contributor Author

Comment 3:

This is not a bug. It would require more work than what the spec is currently requiring
for detecting this case.
go/types also does not report this.
The spec could use clarification.

Status changed to WorkingAsIntended.

@griesemer
Copy link
Contributor Author

Comment 4:

The original example that reported a cycle is probably incorrect. See issue #6703 for
details.

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

3 participants