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-9105] You can't name a nested function the same as a closure parameter. #51602

Open
swift-ci opened this issue Oct 29, 2018 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9105
Radar None
Original Reporter Jessy (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: eabd7cc63a25bf445fcbec92cfa43fc2

relates to:

  • SR-1687 Swift does not warn about shadowing
  • SR-1772 File-level function with the same name as instance function not picked up by compiler

Issue Description:

This comes up for me with asynchronous code, where all of my closures are named `process` and I want the nested functions to have the same name too, though they all differ in signatures due to differing arguments.

Here's an example. Let me know if you need any more details. Thanks!

private func syncWithCloudKit(
  process: @escaping ProcessGet<SetEndpoints>
) {
  CKReferenceCache.requestFromCloudKitAndStore { getCache in
    do {
      let cache = try getCache()
      _process(cache: cache)
    }
    catch { process { throw error } }
  }

  func _process(cache: CKReferenceCache) {
    CKDatabase.private.request(recordType: SetEndpoint.self) { getRecords in
      do {
        let records = try getRecords()
        try _process(cache: cache, records: records)
      }
      catch { process { throw error } }
    }
  }

  func _process(cache: CKReferenceCache, records: [CKRecord]) throws {
    let setEndpoints = try records.map {
      try SetEndpoint(
        record: $0,
        exerciseTypes: cache.exerciseTypes,
        resistanceTypes: cache.resistanceTypes
      )
    }
    try setEndpoints.saveJSONToDrive()
    process {
      [setEndpoints = try SetEndpoint.makeDictionaryFromSavedJSON()]
      in setEndpoints
    }
  }
}
@belkadan
Copy link
Contributor

This seems like another form of shadowing, which means Swift is behaving as expected. (But not desired, I know.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants