[swift-evolution] Make non-void functions @warn_unused_result by default
Pierre Monod-Broca
pierre at monod-broca.fr
Fri Dec 18 06:01:14 CST 2015
I'm also in favor of this proposal.
I'd like to add we would still need a way to define a specific warning message. And sometimes it would make sense to define it for a type. I'm thinking of ReactiveCocoa, where every method returning a Signal as the same @warn_unused_result("did you forget to call 'observe'"). It would be nice to declare this message on the Signal type, and avoid repetition.
Pierre
> Le 18 déc. 2015 à 10:32, Jens Persson via swift-evolution <swift-evolution at swift.org> a écrit :
>
> strong +1 from me. @warn_unused_result is almost always the right answer in the standard library, and the few cases where it isn’t are very easy to notice (when the call has side-effects and the return value is incidental).
>
> -Dave
>
> I'm also in favour of this proposal.
>
> Some days ago, in the swift-dev list ( https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000385.html <https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000385.html> ) I was advised by Chris Lattner to bring a related issue into this discussion:
>
> It's about the lack of a warning for simple statements that are unused and thus meaningless (so most probably unintentional). To demonstrate what I mean, here's a short example that currently compiles without any warnings:
>
> func thisFuncHasNoWarnings(a: Int) {
> a
> "b"
> "c" as Character
> 1.0
> [2.0, 3.0]
> ["four", 5, 6.7] as [Any]
> "Is this"; a; "problem?"
> }
>
> I think it might be reasonable to expect a warning on every single line of that function, no?
> /Jens
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151218/994b82a2/attachment-0001.html>
More information about the swift-evolution
mailing list