[swift-users] Inconsistent behaviour of forward declarations

Dan Cutting dan at cutting.io
Sat Jan 9 16:56:40 CST 2016


Thanks Victor.

Actually, that snippet works in the v2.1.1 REPL as well, so I think the REPL environment works differently.

Both v2.1.1 and v2.2-dev fail when running that code as a script.

Thanks,
Dan


> On 9 Jan 2016, at 10:41 PM, Victor Guerra <vguerra at gmail.com> wrote:
> 
> hi Dan, 
> 
> Seems to work when using Swift 2.2 Snapshot from 6th of jan: 
> 
> Welcome to Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 54dcd16759). Type :help for assistance.
>   1> func foo() -> Int { return soon + 1 } 
>   2. let wat = true 
>   3. let soon = 1
> wat: Bool = true
> soon: Int = 1
>   4> foo()
> $R0: Int = 2
> 
> I am able to reproduce the bug on a playground though where swift 2.1 is used I guess. 
> 
> On Sat, Jan 9, 2016 at 10:44 PM Dan Cutting via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> Hi,
> 
> This code builds and runs fine:
> 
> func foo() -> Int { return soon + 1 }
> let soon = 1
> 
> But the following code has a compilation error (“Use of unresolved identifier ‘soon’”):
> 
> func foo() -> Int { return soon + 1 }
> let wat = true
> let soon = 1
> 
> Any ideas why? Is this a bug in Swift or intended behaviour?
> 
> I might expect either or neither of these to work, but to have one work and one fail is perplexing.
> 
> Thanks,
> Dan
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160109/5f50102b/attachment.html>


More information about the swift-users mailing list