Skip to content

Complete type conversion support for type parameters #1242

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 10 commits into from
Nov 2, 2023

Conversation

nevkontakte
Copy link
Member

This PR adds type conversion support for type parameters that represent slices, structs, arrays, pointers, maps, channels and functions.

It also contains a few incidental bug fixes:

  • Fix a bug in reflect.DeepEqual treatment of channels.
  • Correctly recognize type conversion expressions when desired type has multiple type parameters.
  • Clean up a stray debug print in one of the tests.

Updates #1013

34 failing test cases out of 131 to go...

Broadly, this covers two cases:

 - Slice to pointer-to-array conversions.
 - Conversion between pointers to types with identical underlying types.

Arrays are a special case because pointer to array is a wrapped type,
unlike all other pointer types. Structs are a special case as well
because pointer to struct is actually represented by the same underlying
object as the struct value.
Since in Go they are passed by value, this is essentially equivalent to
copying the value. Even when the type is the same, the copy operation is
needed.
According to the Go spec, channels are equal if they have been created
by the same call to make(). Prior to this change reflect.DeepEqual()
would return false when comparing two channels, one of this is a named
type (e.g. `type ch chan string`) and was created by type conversion
from the other one.

After this change, DeepEquals behavior becomes consistent with the
== operator.

Upstream has a similar bug: golang/go#63886.
…ams.

Prior to this change expressions like `ss[T1, T2](val)` where `ss` is a
parameterized type were not recognized as type conversion expressions
due to use of the *ast.IndexListExpr node.
At this point both remaining issues seem to be related to other kinds of
issues.
@nevkontakte nevkontakte requested a review from flimzy November 1, 2023 23:54
@nevkontakte nevkontakte merged commit 370d8c9 into gopherjs:generics Nov 2, 2023
@nevkontakte nevkontakte deleted the generics12 branch November 2, 2023 11:13
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