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-2474] closure in protocol extension implicitly captures mutating 'self' #45079

Closed
karwa opened this issue Aug 24, 2016 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@karwa
Copy link
Contributor

karwa commented Aug 24, 2016

Previous ID SR-2474
Radar None
Original Reporter @karwa
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift f5f6905

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

md5: fa6db9ecbde8bd4ea55d073a1f378248

duplicates:

Issue Description:

The following code fails to compile since the recent @noescape-by-default changes.

public protocol RangeIndexedCollection {

    associatedtype RangeIndex : Comparable
    associatedtype RangeElement

    typealias TaggedRange = (range: Range<RangeIndex>, tag: RangeElement)
    typealias EditBlock = (_ range: Range<RangeIndex>, _ tag: inout RangeElement?)->(RangeElement?)

    mutating func editTags(in range: Range<RangeIndex>, with block: EditBlock)
}

internal protocol RangeIndexedCollection_WithPostProcessing : RangeIndexedCollection {

    typealias PostProcessingBlock = (TaggedRange, (range: Range<RangeIndex>, tag: RangeElement)?) -> (TaggedRange?, removePrecedingRange: Bool)

    mutating func edit(_ editRange: Range<RangeIndex>,
                       withBlock block: EditBlock,
                       postProcessingBlock: PostProcessingBlock?)
}

extension RangeIndexedCollection_WithPostProcessing where RangeElement : Equatable {

    private func merge(range: (range: Range<RangeIndex>, tag: RangeElement), precedingRange: (range: Range<RangeIndex>, tag: RangeElement)) -> (range: Range<RangeIndex>, tag: RangeElement)? {

        guard precedingRange.range.upperBound == range.range.lowerBound else { return nil }

        if range.tag == precedingRange.tag {

            return (precedingRange.range.lowerBound..<range.range.upperBound, range.tag)
        }
        else {

            // Tags not equal
            return nil
        }
    }

    internal mutating func editAndMerge(_ range: Range<RangeIndex>,
                                        withBlock block: EditBlock) {

        edit(range, withBlock: block)
        {
            (editedTaggedRange:TaggedRange, precedingAdjacentRange:TaggedRange?)->(TaggedRange?,Bool) in

            // Try to merge ranges

            if let precedingAdjacentRange = precedingAdjacentRange,
               let mergedTaggedRange      = self.merge(range: editedTaggedRange, precedingRange: precedingAdjacentRange) {

                return (mergedTaggedRange, true)
            }

            return (nil, false)
        }
    }
}
test.swift:48:36: error: closure cannot implicitly capture a mutating self parameter
                           let mergedTaggedRange      = self.merge(range: editedTaggedRange, precedingRange: precedingAdjacentRange) {
                                                        ^
@karwa
Copy link
Contributor Author

karwa commented Aug 25, 2016

CC @slavapestov, I believe you fixed noescape-ing typealiases recently.

@slavapestov
Copy link
Member

Yeah, typealiases in parameter position are noescape by default now. Is that not what you're observing? Note that the fix did not make it into beta 6, but it's in the swift-3.0-branch now.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants