Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
Ah, yes. Thanks. On Thu, Sep 22, 2016 at 8:29 PM, Joe Groff wrote: > > > On Sep 22, 2016, at 11:28 AM, Jens Persson wrote: > > > > Yes, but should the compiler silently accept that? And is this issue > really related to the other issue? > > No, this is a

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 11:28 AM, Jens Persson wrote: > > Yes, but should the compiler silently accept that? And is this issue really > related to the other issue? No, this is a separate issue. The compiler might be able to catch some obvious cases, but it'd be impossible to

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 11:23 AM, Jens Persson wrote: > > Oh, but how can the following (earlier mentioned) example have anything to do > with Script-mode top-level locals being treated as globals? > > Create "AnotherFile.swift" containing: > func f() -> Int { return a } >

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
Oh, but how can the following (earlier mentioned) example have anything to do with Script-mode top-level locals being treated as globals? Create "AnotherFile.swift" containing: func f() -> Int { return a } let a = f() Create "main.swift" containing: print(a) Compile. Run. For ever. At zero %

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
Thank you for the thorough explanation! /Jens On Thu, Sep 22, 2016 at 7:28 PM, Jordan Rose wrote: > Yep, it really is a long-standing bug. Script-mode top-level locals are > treated as globals (module-scope bindings) by the compiler, but their > initial bindings are

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
Did you see the other code examples that came up in that twitter conversations? For example: This worrying little program compiles: func f() -> Int { return a } let a = f() It also compiles if you print(a) at the end, and it will print 0. If we replace Int with [Int] it will still compile

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Joe Groff via swift-users
> On Sep 21, 2016, at 2:22 PM, Jens Persson via swift-users > wrote: > > // This little Swift program compiles (and runs) fine: > > func foo() -> Int { return a } > let a = 1 > let b = 2 > print(foo()) > > But if `foo()` returns `b` instead of `a`, I get this compile

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Jens Persson via swift-users
I asked the same question on twitter, and it resulted in some interesting finds: https://twitter.com/bitCycle/status/778697998893142016 On Thu, Sep 22, 2016 at 12:41 AM, Zhao Xin wrote: > I suggest you defining the variables before using them like Marco does. > Although from

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Zhao Xin via swift-users
I suggest you defining the variables before using them like Marco does. Although from the global variable point of view, both way should be fine. But the glitch does exist, especially in playground. Zhaoxin On Thu, Sep 22, 2016 at 5:59 AM, Marco S Hyman via swift-users < swift-users@swift.org>

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Marco S Hyman via swift-users
> On Sep 21, 2016, at 2:22 PM, Jens Persson via swift-users > wrote: > > // This little Swift program compiles (and runs) fine: > > func foo() -> Int { return a } > let a = 1 > let b = 2 > print(foo()) > > But if `foo()` returns `b` instead of `a`, I get this compile