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

Restrict signature for getindex(::AbstractString, ::AbstractVector} #20248

Merged
merged 1 commit into from
Feb 6, 2017

Conversation

nalimilan
Copy link
Member

Only integer indices are supported by the generic interface, so better
raise a MethodError for other element types rather than failing later.
Ideally the Bool-specific method would not be needed, but it is required
as long as Bool<:Integer.

Fixes #12495.

(Some of the tests that needed modifications look really weird to me.)

@@ -461,3 +460,7 @@ Base.endof(x::CharStr) = endof(x.chars)
# Case with Unicode characters
@test cmp("\U1f596\U1f596", CharStr("\U1f596")) == 1 # Gives BoundsError with bug
@test cmp(CharStr("\U1f596"), "\U1f596\U1f596") == -1

# issue #12495: logical indexing attempt raises MethodError
Copy link
Member

@KristofferC KristofferC Jan 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment here should say ArgumentError?. It might also be good to be a bit more explicit, for example isue #12495: check that logical indexing attempt raises MethodError so we know if the problem in #12495 was that logical indexing raises the error or that the test is checking that the correct error is being raised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -461,3 +460,7 @@ Base.endof(x::CharStr) = endof(x.chars)
# Case with Unicode characters
@test cmp("\U1f596\U1f596", CharStr("\U1f596")) == 1 # Gives BoundsError with bug
@test cmp(CharStr("\U1f596"), "\U1f596\U1f596") == -1

# issue #12495: logical indexing attempt raises MethodError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's throwing an argumenterror

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I first thought about throwing MethodError but then realized it would be confusing. Fixed.

Only integer indices are supported by the generic interface, so better
raise a MethodError for other element types rather than failing later.
Ideally the Bool-specific method would not be needed, but it is required
as long as Bool<:Integer.
@kshyatt kshyatt added the strings "Strings!" label Jan 26, 2017
@nalimilan
Copy link
Member Author

Will merge tomorrow if nobody objects.

@ararslan ararslan merged commit 1e085b9 into master Feb 6, 2017
@ararslan ararslan deleted the nl/string branch February 6, 2017 03:03
@tkelman
Copy link
Contributor

tkelman commented Feb 7, 2017

Should this have been a deprecation? Any packages using it?

@tkelman tkelman added the needs news A NEWS entry is required for this change label Feb 7, 2017
@nalimilan
Copy link
Member Author

These cases already failed, this PR merely made the error explicit. The only forms which were supported before and now fail are things like "abc"[[true]] considered as equivalent to "abc"[[1]], which are probably not worth supporting.

Sacha0 added a commit to Sacha0/julia that referenced this pull request May 12, 2017
tkelman pushed a commit that referenced this pull request May 13, 2017
@Sacha0 Sacha0 removed the needs news A NEWS entry is required for this change label May 13, 2017
tkelman pushed a commit that referenced this pull request May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants