Repository navigation
Conversation
Generated by 🚫 Danger |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
unhandled_throwing_taskrule flags Tasks whose body only mentionstryinside a nested closure, even when that error can never escape into the Task:Both were reported as unhandled throwing Tasks. The root cause is the rule's
ThrowsVisitor: it walked the whole Task call and descended into every nested closure, counting a closure's owntryandthrowstatements as the Task's. AResultinitializer special case papered over one instance of this.This change starts the traversal at the Task operation's statements and skips nested closure bodies. That stays sound without type information because any error that does escape a nested closure into the Task body has to pass through a
tryorthrowin the body itself: Swift requirestryatrethrowscalls given a throwing closure (soTask { try [1].map { try throwingFunc() } }is still reported), at immediately-invoked throwing closures, and around throwing capture-list initializers, which the visitor still walks. Errors undertry?andtry!count as handled for the whole expression, matching the existing examples. With nested closures skipped generally, theResultspecial case is no longer needed and is removed. Parenthesized andas-cast operation closures passed toTask(operation:)are unwrapped so they keep being checked.The new rule examples cover the two reported false positives plus the cases that must keep triggering: a throwing
mapclosure, a nested Task (only the inner one is reported), and an unhandled throwing capture initializer.Refs #4987. This covers the nested-closure false positives from that issue; the separate case of a throwing Task passed as a function argument is left for a dedicated rule, as discussed there.