Skip to content

CLR arrays don't support negative indexing #503

@antonsynd

Description

@antonsynd

Problem

CLR arrays (array[T]) don't support Python-style negative indexing. arr[-1] throws IndexOutOfRangeException instead of returning the last element.

Sharpy lists handle this via wrapper methods in Sharpy.Core, but CLR arrays use native .NET array indexing which doesn't have this support.

Reproduction

def main():
    arr: array[int] = array[int](3)
    arr[0] = 10
    arr[1] = 20
    arr[2] = 30
    print(arr[-1])  # should print 30
    print(arr[-2])  # should print 20

Expected output:

30
20

Actual: IndexOutOfRangeException at runtime.

Possible Approach

Add a Sharpy.Core wrapper or extension method for array indexing that normalizes negative indices.

Skipped Test

TestFixtures/arrays/array_negative_index.spy — skip reason: "CLR arrays don't support negative indexing natively; needs Sharpy.Core wrapper"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions