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

Tighten signature of repeat to match what's documented #55444

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ function check(arr, inner, outer)
# TODO: Currently one based indexing is demanded for inner !== nothing,
# but not for outer !== nothing. Decide for something consistent.
Base.require_one_based_indexing(arr)
if !all(n -> n isa Integer, inner)
throw(ArgumentError("repeat requires integer counts, got inner = $inner"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this error message may be a lazy string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be. For now I left it just like all others in this check function.

Copy link
Member

Choose a reason for hiding this comment

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

I imagine this branch will DCE much of the time

end
if any(<(0), inner)
throw(ArgumentError("no inner repetition count may be negative; got $inner"))
end
Expand All @@ -526,6 +529,9 @@ function check(arr, inner, outer)
end
end
if outer !== nothing
if !all(n -> n isa Integer, outer)
throw(ArgumentError("repeat requires integer counts, got outer = $outer"))
end
if any(<(0), outer)
throw(ArgumentError("no outer repetition count may be negative; got $outer"))
end
Expand Down
Loading