Skip to content

Fix a typo in slice-to-array conversion tests. #1089

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

Merged
merged 1 commit into from
Dec 16, 2021

Conversation

nevkontakte
Copy link
Member

Some of the tests that were expecting a panic were using a function
literal, but instead of calling it and comparing the result to nil, they
were comparing the function itself.

This change refactors the test to make such a mistake less likely in
future.

Kudos to @dominikh for spotting the bug!

Some of the tests that were expecting a panic were using a function
literal, but instead of calling it and comparing the result to nil, they
were comparing the function itself.

This change refactors the test to make such a mistake less likely in
future.
@nevkontakte nevkontakte requested a review from flimzy November 21, 2021 13:10
nevkontakte referenced this pull request Nov 21, 2021
Conversion is fully supported for slices of numeric types, which is
probably the most common use case for this feature judging by the
discussion in the proposal.

However, it is only partially supported for slices of complex types
(e.g. strings), since they are backed by the JavaScript's built-in Array
type, which lacks ability to share backing memory among subarrays.
Conversion works in cases when the slice is converted into array that
exactly matches the slice's underlying array, but panics if we are
trying to convert a subslice. I feel like an explicit failure is better
than a chance of introducing subtle bugs.

It also seems that GopherJS internally doesn't really distinguish
between array types and pointer to array types, which makes the whole
implementation somewhat messy when it comes to nil vs non-nil pointers
to arrays.

Last but not least, I've moved pointer cache for numeric arrays into the
backing ArrayBuffer, which ensures that pointers are comparable between
different subarrays.
@nevkontakte nevkontakte merged commit 95fae10 into gopherjs:master Dec 16, 2021
@nevkontakte nevkontakte deleted the test-fix branch December 19, 2021 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants