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-5208] Conformance to RangeReplaceableCollection permitted without implementation of replaceSubrange #47784

Closed
hamishknight opened this issue Jun 13, 2017 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@hamishknight
Copy link
Collaborator

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

Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 8242e39473a64a40c660ef8fa30c9216

duplicates:

  • SR-6501 RangeReplaceableCollection default implementations cause infinite recursion

Issue Description:

The following compiles:

struct C : RangeReplaceableCollection {
    
    let startIndex = 0
    let endIndex = 0
    
    func index(after i: Int) -> Int { fatalError() }
    subscript(index: Int) -> String { return "" }
}

var c = C()
c.replaceSubrange(0 ..< 0, with: [])
print(c)

As the default implementation of replaceSubrange that takes an arbitrary RangeExpression and converts it to a Range<Index> is used to satisfy the replaceSubrange requirement – therefore leading to recursion when attempting to call, which isn't particularly intuitive.

Ideally, RangeReplaceableCollection should enforce that replaceSubrange is implemented.

@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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant