diff options
author | Robert Griesemer <gri@golang.org> | 2014-09-29 12:44:50 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-09-29 12:44:50 -0700 |
commit | ef2a8da42c986d3c1c078479f42d5a568a1c3647 (patch) | |
tree | e43172f3fcaae5d7b7492561b2abe8ee2f44309e /doc/cmd.html | |
parent | 2ecbfbd98ac610ea94d5173eabc3b36cb748fe52 (diff) | |
download | go-ef2a8da42c986d3c1c078479f42d5a568a1c3647.tar.gz |
spec: specify variable initialization order explicitly
The existing spec rules on package initialization were
contradictory: They specified that 1) dependent variables
are initialized in dependency order, and 2) independent
variables are initialized in declaration order. This 2nd
rule cannot be satisfied in general. For instance, for
var (
c = b + 2
a = 0
b = 1
)
because of its dependency on b, c must be initialized after b,
leading to the partial order b, c. Because a is independent of
b but is declared before b, we end up with the order: a, b, c.
But a is also independent of c and is declared after c, so the
order b, c, a should also be valid in contradiction to a, b, c.
The new rules are given in form of an algorithm which outlines
initialization order explicitly.
gccgo and go/types already follow these rules.
Fixes issue 8485.
LGTM=iant, r, rsc
R=r, rsc, iant, ken, gordon.klaus, adonovan
CC=golang-codereviews
https://codereview.appspot.com/142880043
Diffstat (limited to 'doc/cmd.html')
0 files changed, 0 insertions, 0 deletions