[swift-evolution] try? shouldn't work on non-method-call
Davor Jankolija
djankolija at gmail.com
Thu Aug 18 12:15:54 CDT 2016
> 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' expression
> try f()
> ^
> ttt.swift:5:8: warning: no calls to throwing functions occur within 'try' expression
> try? f()
> ^
IMHO at least, this should be an error. As a side note I do think that try should have greater precedence than as, even though this does potentially limit calls that would use only one try on a series of throwing statement that can be handled using parentheses. The benefit is that try is probably called in the vast majority of situations (that’s my experience at least) on a single throw statement and having it have higher precedance would avoid some surprises as most developers probably already assume that try wil be executed before as.
— Davor
More information about the swift-evolution
mailing list