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

String.sub throws Invalid_argument("Bytes.sub") " #6557

Closed
vicuna opened this issue Sep 14, 2014 · 6 comments
Closed

String.sub throws Invalid_argument("Bytes.sub") " #6557

vicuna opened this issue Sep 14, 2014 · 6 comments
Milestone

Comments

@vicuna
Copy link

vicuna commented Sep 14, 2014

Original bug ID: 6557
Reporter: oliver
Status: closed (set by @xavierleroy on 2016-12-07T10:36:47Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: PC / Linux
OS: Arch Linux
Version: 4.02.0+beta1 / +rc1
Target version: 4.02.1+dev
Fixed in version: 4.02.1+dev
Category: standard library
Related to: #6560
Monitored by: @gasche @hcarty

Bug description

String.sub throws Invalid_argument("Bytes.sub") when non-valid susbstring found.

Steps to reproduce

In Toplevel:

String.sub;;

  • : string -> int -> int -> string =

String.sub "" 0 1 ;;

Exception: Invalid_argument "Bytes.sub".

@vicuna
Copy link
Author

vicuna commented Sep 14, 2014

Comment author: oliver

OCaml version 4.02.0

@vicuna
Copy link
Author

vicuna commented Sep 24, 2014

Comment author: @gasche

So we have the following options:

A) do nothing
B) try..with (probably too slow)
C) use "String.sub" in the exception for both Bytes.sub and String.sub

The point that the string content of the exception is unspecified is fair, and (A) is therefore a valid choice. But it breaks user code; I'd rather be tempted to try (C). Any opinions?

@vicuna
Copy link
Author

vicuna commented Sep 28, 2014

Comment author: @damiendoligez

I like (C), but we have similar problems with:

fill (which is deprecated)
blit (raises Bytes.blit_string)
index_from
rindex_from
contains_from
rcontains_from

@vicuna
Copy link
Author

vicuna commented Sep 28, 2014

Comment author: @gasche

I'd vote for (C) on all of them.

@vicuna
Copy link
Author

vicuna commented Oct 3, 2014

Comment author: @damiendoligez

Another possibility:

D) raise Invalid_argument "String.sub / Bytes.sub"

@vicuna
Copy link
Author

vicuna commented Oct 10, 2014

Comment author: @damiendoligez

Fixed in branch 4.02 (commit 15520) with solution D. People who match on the string will have a bad surprise but we'll explain that they shouldn't do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant