Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Braeden Profile via swift-evolution
I do think that the status quo is good for try? precedence and such, but how about the original problem? The code was hard to work with because it used a double nested Optional. If you really don’t care about the reason that code failed, then a single optional should be returned. There’s this:

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Xiaodi Wu via swift-evolution
On Thu, Aug 18, 2016 at 1:20 PM, John McCall wrote: > On Aug 18, 2016, at 10:11 AM, Xiaodi Wu wrote: > On Thu, Aug 18, 2016 at 11:30 AM, John McCall wrote: > >> On Aug 18, 2016, at 8:46 AM, Xiaodi Wu wrote: >> The issue would be that, in the case of "try? foo()", nil and .some(nil) >> might me

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread John McCall via swift-evolution
> On Aug 18, 2016, at 10:11 AM, Xiaodi Wu wrote: > On Thu, Aug 18, 2016 at 11:30 AM, John McCall > wrote: >> On Aug 18, 2016, at 8:46 AM, Xiaodi Wu > > wrote: >> The issue would be that, in the case of "try? foo()", nil and .some(nil) >> mig

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread John McCall via swift-evolution
> On Aug 18, 2016, at 10:56 AM, Davor Jankolija wrote: >> On 18 Aug 2016, at 19:46, John McCall > > wrote: >> >>> On Aug 18, 2016, at 10:15 AM, Davor Jankolija via swift-evolution >>> mailto:swift-evolution@swift.org>> wrote: >>> This is a warning right now — do

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Davor Jankolija via swift-evolution
> On 18 Aug 2016, at 19:46, John McCall wrote: > >> On Aug 18, 2016, at 10:15 AM, Davor Jankolija via swift-evolution >> wrote: >> >>> This is a warning right now — do you think it should be an error? >>> >>> Slavas-MacBook-Pro:~ slava$ cat ttt.swift >>> func f() {} >>> >>> func g() { >>>

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread John McCall via swift-evolution
> On Aug 18, 2016, at 10:15 AM, Davor Jankolija via swift-evolution > wrote: > >> This is a warning right now — do you think it should be an error? >> >> Slavas-MacBook-Pro:~ slava$ cat ttt.swift >> func f() {} >> >> func g() { >> try f() >> try? f() >> } >> >> Slavas-MacBook-Pro:~ slava$ sw

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Davor Jankolija via swift-evolution
> This is a warning right now — do you think it should be an error? > > Slavas-MacBook-Pro:~ slava$ cat ttt.swift > func f() {} > > func g() { > try f() > try? f() > } > > Slavas-MacBook-Pro:~ slava$ swiftc ttt.swift > ttt.swift:4:3: warning: no calls to throwing functions occur within 'try

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Xiaodi Wu via swift-evolution
On Thu, Aug 18, 2016 at 11:30 AM, John McCall wrote: > On Aug 18, 2016, at 8:46 AM, Xiaodi Wu wrote: > The issue would be that, in the case of "try? foo()", nil and .some(nil) > might mean very different things. > > > This is true of a?.foo() as well. But yes, I think it is more likely that > s

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread John McCall via swift-evolution
> On Aug 18, 2016, at 8:46 AM, Xiaodi Wu wrote: > The issue would be that, in the case of "try? foo()", nil and .some(nil) > might mean very different things. This is true of a?.foo() as well. But yes, I think it is more likely that someone would want to treat them differently for try?. John.

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Xiaodi Wu via swift-evolution
The issue would be that, in the case of "try? foo()", nil and .some(nil) might mean very different things. On Thu, Aug 18, 2016 at 10:40 John McCall wrote: > On Aug 18, 2016, at 8:19 AM, Xiaodi Wu via swift-evolution < > swift-evolution@swift.org> wrote: > > Lots of interesting points here. I do

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread John McCall via swift-evolution
> On Aug 18, 2016, at 8:19 AM, Xiaodi Wu via swift-evolution > wrote: > > Lots of interesting points here. I do think there's an improvement possible > here, but it's actually along the lines of Sam's original suggestion #3 (not > vis-a-vis all of Swift, but specifically for how try? composes

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Xiaodi Wu via swift-evolution
On Thu, Aug 18, 2016 at 10:19 AM, Xiaodi Wu wrote: > Lots of interesting points here. I do think there's an improvement > possible here, but it's actually along the lines of Sam's original > suggestion #3 (not vis-a-vis all of Swift, but specifically for how try? > composes with as?): > > A. I'm

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Xiaodi Wu via swift-evolution
Lots of interesting points here. I do think there's an improvement possible here, but it's actually along the lines of Sam's original suggestion #3 (not vis-a-vis all of Swift, but specifically for how try? composes with as?): A. I'm in favor of the current behavior where try prefixes an entire st

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Sikhapol Saijit via swift-evolution
> On Aug 18, 2016, at 3:42 PM, Slava Pestov wrote: > >> >> On Aug 18, 2016, at 12:52 AM, David Hart via swift-evolution >> mailto:swift-evolution@swift.org>> wrote: >> >> Opinions inline: >> >>> On 18 Aug 2016, at 07:43, Sikhapol Saijit via swift-evolution >>> mailto:swift-evolution@swift.o

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Slava Pestov via swift-evolution
> On Aug 18, 2016, at 1:42 AM, Slava Pestov via swift-evolution > wrote: > >> >> On Aug 18, 2016, at 12:52 AM, David Hart via swift-evolution >> mailto:swift-evolution@swift.org>> wrote: >> >> Opinions inline: >> >>> On 18 Aug 2016, at 07:43, Sikhapol Saijit via swift-evolution >>> mailto:

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Slava Pestov via swift-evolution
> On Aug 18, 2016, at 12:52 AM, David Hart via swift-evolution > wrote: > > Opinions inline: > >> On 18 Aug 2016, at 07:43, Sikhapol Saijit via swift-evolution >> mailto:swift-evolution@swift.org>> wrote: >> >> Hi all, >> >> >> Yesterday I tried this code: >> >> func couldFailButWillNot()

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Sikhapol Saijit via swift-evolution
> On Aug 18, 2016, at 3:15 PM, Charles Srstka wrote: > > Sorry for the resend! Some of my previous e-mail was left out for some > reason. Here it is again, as it should have been: > >> On Aug 18, 2016, at 12:43 AM, Sikhapol Saijit via swift-evolution >> mailto:swift-evolution@swift.org>> wrot

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Charles Srstka via swift-evolution
Sorry for the resend! Some of my previous e-mail was left out for some reason. Here it is again, as it should have been: > On Aug 18, 2016, at 12:43 AM, Sikhapol Saijit via swift-evolution > mailto:swift-evolution@swift.org>> wrote: > > 1. Is it intentional that try? can be used with a "non-met

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread Charles Srstka via swift-evolution
> On Aug 18, 2016, at 12:43 AM, Sikhapol Saijit via swift-evolution > wrote: > > 1. Is it intentional that try? can be used with a "non-method-call" and > return an optional of the type that follows? a. I’m not sure what you mean by “non-method-call”, since the thing you called in your exampl

Re: [swift-evolution] try? shouldn't work on non-method-call

2016-08-18 Thread David Hart via swift-evolution
Opinions inline: > On 18 Aug 2016, at 07:43, Sikhapol Saijit via swift-evolution > wrote: > > Hi all, > > > Yesterday I tried this code: > > func couldFailButWillNot() throws -> Any { > return 42 > } > > if let a = try? couldFailButWillNot() as? Int { > print(a) > } > > And was sur

[swift-evolution] try? shouldn't work on non-method-call

2016-08-17 Thread Sikhapol Saijit via swift-evolution
Hi all, Yesterday I tried this code: func couldFailButWillNot() throws -> Any { return 42 } if let a = try? couldFailButWillNot() as? Int { print(a) } And was surprised that the output was Optional(42) on both Swift 2 and Swift 3. I always have the impression that when a variable is re