Skip to content

[Bug or FeatureRequest]: collection.rotate(toStartAt: Int) crashes with negative argument #239

Open
@Loradim

Description

@Loradim

Replace this paragraph with a short description of the incorrect incorrect behavior. If this is a regression, please note the last version that the behavior was correct in addition to your current version.

Swift Algorithms version:
1.2.0 (= main branch currently)

Swift version:
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

calling .rotate(toStartAt: ) with a negative number causes a run-time error

var array = [1, 2, 3, 4, 5, 6, 7, 8]
array.rotate(toStartAt: -2)

Expected behavior

This function shouldn't crash. Considering what .rotate() does (positive values rotate elements to the left) being called with a negative value should rotate to the right.
Another option would be to only allow for positive values as arguments, e.g. UInt as parameter.

Actual behavior

Code crashes with an fatal error:
Swift/arm64e-apple-macos.swiftinterface:16236: Fatal error: Range requires lowerBound <= upperBound

Kind regards,
Heiko

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