1+ // This is explicitly called out as not supported in the source code right now,
2+ // so let's be sure to solidify that semantic with a test case.
3+ //
4+ // Basically, the cyclic checks are & will remain, by and large, *syntactic*,
5+ // rather than truly deep analysis of the semantics. The initializer of a
6+ // *syntactically* refers to a_fun which refers to a, even though the initializer
7+ // of a does not ever *semantically* actually refer to itself.
8+ //
9+ // This is still considered an error, because otherwise you have to do things
10+ // like escape analysis, and the definition of valid code becomes very complicated
11+ // and prone to change.
12+ //
13+ // This simpler, but more restrictive semantics, is at least easy to understand,
14+ // which is good for the compiler and the programmer. In particular, if the main
15+ // relationship creating cycles is *syntactic reference* to a variable, then it
16+ // becomes very clear that to break the cycle simply means to remove one of the
17+ // syntactic references in the chain, rather than to carefully micromanage the
18+ // semantics of every function in the chain.
19+ //
20+ // And, of course, there's really no reason a variable initializer should depend
21+ // on a function that depends on that variable. If you really must, you can just
22+ // initialize the variable to a dummy value then call the "real" initializer in
23+ // init(). (Could be inconvenient for option types, but I really am willing to
24+ // make that sacrifice).
25+
26+ //? Cycle in variable initialization order
27+
28+ var a = {
29+ var b = a_fun;
30+ 10;
31+ };
32+
33+ fun a_fun() { print(a); }
0 commit comments