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-14848] A Collection without any subscript[Range<Index>] can compile #57195
Comments
@swift-ci create |
It looks like this is because the `Collection.init<R: RangeExpression>(r: R)` extension technically satisfies the `Collection.init(bounds: Range)` requirement, so it leads to infinite recursion. Aaargh. Something like the solution we applied to the `RandomNumberGenerator.next()` case could perhaps resolve this. |
I see. For reference, from stdlib's Range.swift: extension Collection {
public subscript<R: RangeExpression>(r: R)
-> SubSequence where R.Bound == Index {
return self[r.relative(to: self)] // <- accidental recursion when
// there is no other range subscript
}
} |
Check with the release version of 5.5 before closing. |
This standard library bug allowed incomplete
The first 3 meant that a utility subscript ( The fix therefore converts a latent runtime bug to a compilation error. |
I just ran into this bug while working on a personal project. Using the latest development snapshot, the fix for the getter on |
The |
I see. Thanks for responding. |
Attachment: Download
Environment
swift-driver version: 1.26 Apple Swift version 5.5 (swiftlang-1300.0.20.104 clang-1300.0.21.1)
Target: arm64-apple-macosx11.0
Additional Detail from JIRA
md5: e982e40416288e077649666cd5387791
Issue Description:
Collection
has the following requirement:Its only default implementation is in an
extension Collection where SubSequence == Slice<Self>
. Therefore it should be required to supply such a subscript in order to compile aCollection
whoseSubSequence
is notSlice
. Somehow, it isn't! However, trying to access such an un-defined subscript results in a crash at runtime, even though it had compiled successfully.Instructions:
$ swiftc myrange.swift
$ ./myrange
Segmentation fault: 11
The .swift file is included, for convenience.
The text was updated successfully, but these errors were encountered: