-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: FlattenIntoArray
: add assertions
#1620
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to assert that
_target_
is an Array exotic object, but I think because ofArraySpeciesCreate
I can't.
I think you're right. That is, the result of ArraySpeciesCreate
(ignoring abrupts) isn't guaranteed to be an Array (despite what its preamble says), because a subclass of Array could override its @@species
property to return a non-Array constructor?
spec.html
Outdated
1. Assert: Type(_source_) is Object. | ||
1. Assert: _sourceLen_ is an integer Number ≥ 0. | ||
1. Assert: _start_ is an integer Number ≥ 0. | ||
1. Assert: _depth_ is an integer Number ≥ 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When A.p.flat
invokes this operation, the value passed to _depth_
can be any normal return from ToInteger
, which includes negative integers and also some odd values like +/- zero and +/- infinity. The infinities fail the "integer" part of this assertion, and the negative integers fail the ≥ 0
part. Maybe change to:
Assert: _depth_ is an integer Number or *+∞* or *-∞*.
Alternatively, A.p.flat
could at least map all negatives to (positive) zero. Then you could say:
Assert: _depth_ is either *+∞* or an integer Number ≥ 0.
(Tangent: I was going to complain about _depth_ - 1
when _depth_
is +infinity, but I guess it became well-defined with the merge of PR #1135 ("an operation with no subscript is interpreted to be a Number operation"). However, it might be worth a Note.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively,
A.p.flat
could at least map all negatives to (positive) zero.
I like this suggestion a lot.
eb35757
to
e893b3b
Compare
e893b3b
to
6136ace
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me.
6136ace
to
4bac90f
Compare
Add some assertions to clarify the intended usage of this abstract operation.
I wanted to assert that
target
is an Array exotic object, but I think because ofArraySpeciesCreate
I can't.