Skip to content

[SR-10299] RangeExpression's relative(to:) crashes on partial ranges #52699

@swift-ci

Description

@swift-ci
Previous ID SR-10299
Radar None
Original Reporter gpambrozio (JIRA User)
Type Bug
Environment

Playground running on XCode 10.2 GM

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

md5: 1658d7d4fcd057072ea901fa5d7d095b

Issue Description:

I noticed that if you have a partial range and you call relative(to🙂 with a collection that does not contain the range's specified bound you get a fatalError

This is a simple playground that shows the problem:

let emptyCollection = [Int]()
let nonEmptyCollection = (0..<20).map { $0 }
let arraySlice = nonEmptyCollection[5...]

let partialRangeFrom = 1...
let partialRangeUpTo = ..<1
let partialRangeThrough = ...1

partialRangeFrom.relative(to: emptyCollection)
partialRangeUpTo.relative(to: arraySlice)
partialRangeThrough.relative(to: arraySlice)

The playground will crash on the first relative(to🙂 call but if you comment that out it crashes on the next and so on.

I have found a simple fix for the issue and am submitting a pull request with the change and tests that would crash as it is now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions