Skip to content

proposal: go/types: adopt "defined type" terminology consistently #65855

@adonovan

Description

@adonovan

The spec uses the term "defined type" for a type created by a declaration such as type T int; a defined type is capable of bearing declared methods. Historically, this was called a Named type, but the advent of type aliases made this confusing and ambiguous.

Though I was initially lukewarm about the term "defined type" (aren't all types defined?), recent work auditing dense type-checking code in x/tools as made me appreciate it, because there are now three kinds of "named" types:

  • defined types (*Named)
  • type parameters (*TypeParam, go1.18), and
  • type aliases (*Alias in go1.22).

In some cases, their namedness is a meaningful commonality that can be used by tooling. For example, they all have an associated TypeName symbol that provides their location and logical name for use in a tool's UI.

I propose that we follow through with the renaming, using the name "Named" as little as possible. Obviously we can't get rid of Named, or make it an alias for Defined (as its reflect.Type.String would change), but we can make Defined an alias for it:

// A Defined type is a type created by a declaration such as `type T underlying`,
// capable of bearing method declarations.
//
// Along with TypeParam and Alias, it is one of three types that are named
// and have an associated TypeName symbol.
// Named is a historical and deprecated term for Defined.
type Defined = types.Named
func NewDefined(obj *TypeName, underlying Type, methods []*Func) *Defined

// Named is the historical term for a Defined type.
// Use Defined in new code.
type Named struct { ... }

// Deprecated: use NewDefined.
func NewNamed( ... ) { return NewDefined ... }

Metadata

Metadata

Labels

Type

No type

Projects

Status

Incoming

Relationships

None yet

Development

No branches or pull requests

Issue actions