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 second argument of size and axes to Integer for most types #30702

Merged
merged 1 commit into from
Jan 23, 2019

Conversation

JeffBezanson
Copy link
Sponsor Member

This argument had a variety of strange behaviors:

julia> size([1], Int8(1))
ERROR: TypeError: in arraysize, expected Int64, got Int8

julia> size((), Int8(1))
0

julia> size((), :x)
ERROR: ArgumentError: invalid tuple dimension x

julia> size((1,), 1.0)
1

julia> size(1, :x)
ERROR: MethodError: Cannot `convert` an object of type Symbol to an object of type Int64

After:

julia> size([1], Int8(1))
1

julia> size((), Int8(1))
0

julia> size((), :x)
ERROR: MethodError: no method matching size(::Tuple{}, ::Symbol)

julia> size((1,), 1.0)
ERROR: MethodError: no method matching size(::Tuple{Int64}, ::Float64)

julia> size(1, :x)
ERROR: MethodError: no method matching size(::Int64, ::Symbol)

@JeffBezanson JeffBezanson added domain:arrays [a, r, r, a, y, s] kind:minor change Marginal behavior change acceptable for a minor release labels Jan 12, 2019
@@ -602,7 +602,7 @@ function ascii(s::String)
end
return s
end
@noinline __throw_invalid_ascii(s, i) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
@noinline __throw_invalid_ascii(s::String, i::Int) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This seems like a mostly-unrelated change; is this just cleanup? Do the type arguments help codegen because of @noinline?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Yes, it's unrelated. Just good style to write the types since we know them exactly.

@JeffBezanson
Copy link
Sponsor Member Author

Ok, this shouldn't be done for the AbstractArray fallback since it will introduce new ambiguities. Changed to a typeassert instead.

@JeffBezanson JeffBezanson merged commit d821a11 into master Jan 23, 2019
@JeffBezanson JeffBezanson deleted the jb/sizeargs branch January 23, 2019 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] kind:minor change Marginal behavior change acceptable for a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants