<div dir="ltr">Did you see the other code examples that came up in that twitter conversations?<div>For example:</div><div><br></div><div>This worrying little program compiles:</div><div><div>func f() -> Int {</div><div> return a</div><div>}</div><div>let a = f()</div></div><div><br></div><div><br></div><div>It also compiles if you print(a) at the end, and it will print 0.</div><div><br></div><div>If we replace Int with [Int] it will still compile but crash when run.</div><div><br></div><div>And also this:</div><div><br></div><div>AnotherFile.swift containing:</div><div><div><div>func f() -> Int {</div><div> return a</div><div>}</div><div>let a = f()</div></div></div><div><br></div><div>main.swift containing</div><div>print(a)</div><div><br></div><div>Compile, run (for eternity, at 0% CPU).</div><div><br></div><div>/Jens</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 22, 2016 at 3:13 AM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Sep 21, 2016, at 2:22 PM, Jens Persson via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
><br>
</span><div><div class="h5">> // This little Swift program compiles (and runs) fine:<br>
><br>
> func foo() -> Int { return a }<br>
> let a = 1<br>
> let b = 2<br>
> print(foo())<br>
><br>
> But if `foo()` returns `b` instead of `a`, I get this compile time error:<br>
> "Use of unresolved identifier `b`"<br>
<br>
</div></div>This looks like a bug to me (cc-ing Jordan, who's thought about global scoping issues more than me). In "script mode", it shouldn't be possible to refer to a variable before its initialization is executed. However, the way this is currently modeled is…problematic, to say the least, among other reasons because script globals are still visible to "library" files in the same module.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Joe</font></span></blockquote></div><br></div>