Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5455] Compiler not able to provide automatic fix-it for returning closure #48027

Closed
swift-ci opened this issue Jul 14, 2017 · 0 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5455
Radar None
Original Reporter mkchoi212 (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode Version 9.0 beta 3 (9M174d) on macOS Version 10.12.5 (16F73)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 0a98c7b07e7ad0568d85805fd24092d5

duplicates:

Issue Description:

The compiler is not providing automatic fix-it suggestions for returning closures that are not properly labeled with a `@escaping` keyword.

For example, here is an incorrect version of a function that requires two `@escaping` keywords to be inserted.

func mapping <A, B, C> (f: (A) -> (B)) -> ((C, B) -> (C)) -> ((C, A) -> (C))

Despite the complexity, the compiler manages to catch two errors but fails to provide a fix-it for the latter.

1. Closure use of non-escaping parameter `f` may allow it to escape
 a. Automatic Fix-it by doing `f: @escaping (A) - > (B)`

2. Closure use of non-escaping parameter `reducer` may allow it to escape
 b. No Fix-it provided

As you see above, the two places where a compile-time error occurred had the same exact problem; they both needed a `@escaping`. However, while the function parameter was offered an automatic fix-it, the nested closure being returned was not.

Here’s the correct version of the function.

func mapping <A, B, C> (f: @escaping (A) -> (B)) -> (@escaping ((C, B) -> (C))) -> ((C, A) -> (C)) {
    return { reducer in
        return { accum, input in
            reducer(accum, f(input))
        }
    }
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant