Skip to content

ClosedRange.upperBound reports incorrect value #30

@marcprux

Description

@marcprux

Range.lowerBound and Range.upperBound is correct for open ranges:

let rangeExclusiveInt = 1..<3
XCTAssertEqual(rangeExclusiveInt.lowerBound, 1)
XCTAssertEqual(rangeExclusiveInt.upperBound, 3)

But for ClosedRange, the upperBound is incorrect: Swift expects 1...3 to be 3, but SkipLib reports 4:

let rangeInclusiveInt = 1...3
XCTAssertEqual(rangeInclusiveInt.lowerBound, 1)
XCTAssertEqual(rangeInclusiveInt.upperBound, 3) // java.lang.AssertionError: 4 != 3

The reason is that we always translate upperBound into endInclusive + 1, since we assume open ranges. Kotlin doesn't distinguish between open ranges and closed ranges (they are both IntRange), so I'm not sure if there is any way of handling this correctly short of having our own independent Range structures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions