Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Complete support for slice-to-array conversion. #1057

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 5 commits into from
Sep 13, 2021

Conversation

nevkontakte
Copy link
Member

This PR contains several changes that finalize support for converting slices into underlying arrays.

  • Fixed a bug where named array pointer types were created with a wrong JavaScript constructor function
  • Fixed a bug in the reflect package where we were using an incorrect constructor when converting array pointer types.
  • Patched Value.CanConvert() to avoid use of unsafeheader.Slice.

At this point all reflect tests are passing, as well as all slice-to-array conversion tests \o/

By the spec, `arrPtr[i]` is a shortcut for `(*arrPtr)[i]`, where
`arrPtr` is a variable of an array pointer type, such as `*[1]int`.
Rewriting AST in this way concentrates all logic for pointer
dereferencing in one place, which should make future refactorings
simpler.
...and also document what "wrapped" types are about, because it took me
a looong time to figure out. Turns out this is pretty much a form of
primitive type boxing that is done in languages like Java.

Array-pointer types are one of the wrapped types, which means they are
represented by a native JS type at runtime, except for a few situations
when access to the full Go type needs to be preserved. To wrap such a
value, the native value is passed as a single constructor argument, but
named array pointer types did not provide that, using a default
constructor for all pointer types.
Array pointers are the only kind of pointer considered a "wrapped", so
they need to be handled appropriately. At runtime an array pointer is
represented by a reference to the JavaScript native array object, so we
only need to copy the reference and couple it with the desired Go type.
It will be boxed into the new Go type if/when the compiler needs it down
the road.
Upstream uses a conversion to unsafeheader.Slice, which isn't supported
by GopherJS. Using Value.Len() is preferrable, since we already override
it to provide compatibility. If/when
golang/go#48346 gets into the stable release,
this patch will no longer be necessary.
@nevkontakte nevkontakte requested a review from flimzy September 12, 2021 18:27
@nevkontakte nevkontakte merged commit 6a42cad into gopherjs:wip-go1.17 Sep 13, 2021
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