Skip to content

go/types: additions to support type parameters #47916

Closed
@findleyr

Description

@findleyr

This proposal formally introduces the changes we've made to support parameterized functions and types in go/types. See the full write-up here:
https://go.googlesource.com/proposal/+/master/design/47916-parameterized-go-types.md

Also see the corresponding proposal for go/ast and go/token: #47781.

Any feedback is appreciated. In recognition that this proposal contains a large new API surface, we will not start to evaluate whether discussion is resolved at least a few weeks. If there appears to be consensus that a change is required to the original proposal, we'll update the document and add a note here.

CC @griesemer

Changelog: (changes from the initial proposal)

  • TParamList was renamed to TypeParamList
  • TParams fields were renamed to TypeParams
  • TArgs was renamed to TypeArgs
  • RParams was renamed to RecvTypeParams
  • Orig was renamed to Origin
  • Info.Inferred was renamed to Info.Instances, changed to use the *ast.Ident as key, and updated to capture all type and signature instantiation.
  • ArgumentError was tweaked to be more idiomatic.
  • Environment was renamed to Context
  • Setters on the *Signature type were replaced with a new constructor: NewSignatureType
  • The TypeParams.Index accessor was added.
  • Interface.IsConstraint was replaced by Interface.IsMethodSet.

Note: there are a few caveats/discrepancies in the current implementation. I'll keep this updated as they are resolved to coincide with the proposal.

  • Instantiate will panic if passed anything other than a *Named or *Signature type, or with incorrect length targs. In the proposal we decided to instead make this return an error, but that is not yet done.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions