You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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).
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.
The text was updated successfully, but these errors were encountered: