Skip to content
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

array::copy(from, start, to, offset, length) copies one element more #508

Open
marzipankaiser opened this issue Jun 25, 2024 · 0 comments
Open
Labels
area:stdlib bug Something isn't working good first issue Good for newcomers

Comments

@marzipankaiser
Copy link
Contributor

According to the documentation:

/**
 * Copies `length`-many elements from `from` to `to`
 * starting at `start` (in `from`) and `offset` (in `to`)
 */
def copy[T](from: Array[T], start: Int, to: Array[T], offset: Int, length: Int): Unit / Exception[OutOfBounds]

However, actually:

import array

def main() = {
  with on[OutOfBounds].panic

  val a = array(10, 0)
  val b = array(10, 1)

  copy(a, 0, b, 0, 5)
  println(b)
}

consistently outputs:

Array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1)

(i.e., with 6 times 0 instead of 5) in all backends I tried.

Probably, here:

if (length >= 0) {

it should be > instead of >=.

@marzipankaiser marzipankaiser added bug Something isn't working area:stdlib good first issue Good for newcomers labels Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:stdlib bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant