aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorMark Freeman <mark@golang.org>2025-08-13 14:55:50 -0400
committerGopher Robot <gobot@golang.org>2025-11-13 12:54:47 -0800
commit7a372affd9eb4af18c3e2a0ce4d61f23ca1305d5 (patch)
tree1f3daea17d066f818caafb3842a60eb2c1518159 /src/cmd
parent57362e98140bdb964d05017690fb0aba37af6b48 (diff)
downloadgo-7a372affd9eb4af18c3e2a0ce4d61f23ca1305d5.tar.xz
go/types, types2: rename definedType to declaredType and clarify docs
declaredType seems a better name for this function because it is reached when processing a (Named or Alias) type declaration. In both cases, the fromRHS field (rather than the underlying field) will be set. Change-Id: Ibb1cc338e3b0632dc63f9cf2fd9d64cef6f1aaa5 Reviewed-on: https://go-review.googlesource.com/c/go/+/695955 Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/types2/decl.go4
-rw-r--r--src/cmd/compile/internal/types2/typexpr.go20
2 files changed, 12 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go
index 91d2492a53..8f196ece61 100644
--- a/src/cmd/compile/internal/types2/decl.go
+++ b/src/cmd/compile/internal/types2/decl.go
@@ -532,7 +532,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *TypeN
check.collectTypeParams(&alias.tparams, tdecl.TParamList)
}
- rhs = check.definedType(tdecl.Type, obj)
+ rhs = check.declaredType(tdecl.Type, obj)
assert(rhs != nil)
alias.fromRHS = rhs
@@ -576,7 +576,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *TypeN
check.collectTypeParams(&named.tparams, tdecl.TParamList)
}
- rhs = check.definedType(tdecl.Type, obj)
+ rhs = check.declaredType(tdecl.Type, obj)
assert(rhs != nil)
named.fromRHS = rhs
diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go
index 8601ce6277..303f782ac4 100644
--- a/src/cmd/compile/internal/types2/typexpr.go
+++ b/src/cmd/compile/internal/types2/typexpr.go
@@ -16,7 +16,7 @@ import (
// ident type-checks identifier e and initializes x with the value or type of e.
// If an error occurred, x.mode is set to invalid.
-// For the meaning of def, see Checker.definedType, below.
+// For the meaning of def, see Checker.declaredType, below.
// If wantType is set, the identifier e is expected to denote a type.
func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType bool) {
x.mode = invalid
@@ -149,14 +149,14 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
// typ type-checks the type expression e and returns its type, or Typ[Invalid].
// The type must not be an (uninstantiated) generic type.
func (check *Checker) typ(e syntax.Expr) Type {
- return check.definedType(e, nil)
+ return check.declaredType(e, nil)
}
// varType type-checks the type expression e and returns its type, or Typ[Invalid].
// The type must not be an (uninstantiated) generic type and it must not be a
// constraint interface.
func (check *Checker) varType(e syntax.Expr) Type {
- typ := check.definedType(e, nil)
+ typ := check.declaredType(e, nil)
check.validVarType(e, typ)
return typ
}
@@ -187,11 +187,11 @@ func (check *Checker) validVarType(e syntax.Expr, typ Type) {
}).describef(e, "check var type %s", typ)
}
-// definedType is like typ but also accepts a type name def.
-// If def != nil, e is the type specification for the type named def, declared
-// in a type declaration, and def.typ.underlying will be set to the type of e
-// before any components of e are type-checked.
-func (check *Checker) definedType(e syntax.Expr, def *TypeName) Type {
+// declaredType is like typ but also accepts a type name def.
+// If def != nil, e is the type specification for the [Alias] or [Named] type
+// named def, and def.typ.fromRHS will be set to the [Type] of e immediately
+// after its creation.
+func (check *Checker) declaredType(e syntax.Expr, def *TypeName) Type {
typ := check.typInternal(e, def)
assert(isTyped(typ))
if isGeneric(typ) {
@@ -230,7 +230,7 @@ func goTypeName(typ Type) string {
}
// typInternal drives type checking of types.
-// Must only be called by definedType or genericType.
+// Must only be called by declaredType or genericType.
func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) {
if check.conf.Trace {
check.trace(e0.Pos(), "-- type %s", e0)
@@ -296,7 +296,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) {
case *syntax.ParenExpr:
// Generic types must be instantiated before they can be used in any form.
// Consequently, generic types cannot be parenthesized.
- return check.definedType(e.X, def)
+ return check.declaredType(e.X, def)
case *syntax.ArrayType:
typ := new(Array)