You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.typeDefined= types.NamedfuncNewDefined(obj*TypeName, underlyingType, methods []*Func) *Defined// Named is the historical term for a Defined type.// Use Defined in new code.typeNamedstruct { ... }
// Deprecated: use NewDefined.funcNewNamed( ... ) { returnNewDefined ... }
The text was updated successfully, but these errors were encountered:
Interesting. I think we've long considered "Named" to have been a misnomer, but not considered changing it. FWIW, I'm not sure that compatibility prohibits Named from being an alias for Defined. Also, predeclared basic types are also named (https://go.dev/ref/spec#Types).
I guess the question is whether this is worth trying to change at this point, or whether it is simpler to continue to live with Named. I think there are many things we would change in the go/types API if we could, and such a superficial change may not be worth the churn.
It looks the latest spec has almost cleared the confusions. Named types include predeclared types, defined types (including ordinary and generic ones), and type parameters. An instantiated type is an ordinary defined type (so also a named type). An alias to an unnamed composite type is not a named type.
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 aNamed
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:
*Named
)*TypeParam
, go1.18), and*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:The text was updated successfully, but these errors were encountered: