Re: Swift struggles with arithmetic ?
Re: Swift struggles with arithmetic ?
- Subject: Re: Swift struggles with arithmetic ?
- From: Charles Srstka <email@hidden>
- Date: Sat, 29 Aug 2015 16:07:36 -0500
> On Aug 29, 2015, at 3:05 PM, Gavin Eadie <email@hidden> wrote:
>
> Apologies if off-topic, but Swift appears a lot on cocoa-dev, so maybe it’s OK
>
> I’ve been using Swift and moving some Obj-C code over to it, but I’m concerned that it thinks this is “too complex to be solved in reasonable time”:
>
> import Foundation
> let y = 1.0 * sin(1.0) + 1.0 * sin(1.0) + 1.0 * sin(1.0)
>
> The above is simplified from the original (original didn’t have constants under the sin function). Swift 2.0 (Version 7.0 beta 6) reports a fatal error and suggests breaking down the expression which, of course, I can do but. I’ve not seen any reports of such behavior on this list or elsewhere; have you?
>
> There’s a Radar report for this filed against Swift 1.2 (and updated for 2.0).
Due to type inference and operator overloading, figuring out what to do with + is hard for the compiler. This line:
let foo: [Int] = [] + [] + [] + [] + []
will generate the “too complex to be solved in reasonable time” error, and if you break it up like this:
let foo = [Int]()
let bar = [Int]()
let baz = [Int]()
let qux = [Int]()
let xyzzy = [Int]()
let plugh = foo + bar + baz + qux + xyzzy
it will compile, but it takes over a minute to do so on my Retinabook.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden