]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: expand documentation for Info.Types map
authorRobert Griesemer <gri@golang.org>
Mon, 6 Jan 2025 21:25:08 +0000 (13:25 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 7 Jan 2025 17:56:11 +0000 (09:56 -0800)
Function types for function (and method) declarations do not
appear in Info.Types maps, only Info.Defs maps, because the
function type is implicit in the declaration and not a proper
(function) type expression. This is true even though the AST
represents these types via an (artificial) FuncType node.

Document this explicitly in the API.

No functional code changes.

Fixes #70908.

Change-Id: I2aa897daed04e7ad0fa8b625d9adc7b423c57387
Reviewed-on: https://go-review.googlesource.com/c/go/+/640776
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/types2/api.go
src/go/types/api.go

index 74c549076df0904515ad1c4f6c47e15c77a280be..49cc0e54ecf750294cbdd63dd230fb60a3875108 100644 (file)
@@ -208,11 +208,19 @@ type Info struct {
        //
        // The Types map does not record the type of every identifier,
        // only those that appear where an arbitrary expression is
-       // permitted. For instance, the identifier f in a selector
-       // expression x.f is found only in the Selections map, the
-       // identifier z in a variable declaration 'var z int' is found
-       // only in the Defs map, and identifiers denoting packages in
-       // qualified identifiers are collected in the Uses map.
+       // permitted. For instance:
+       // - an identifier f in a selector expression x.f is found
+       //   only in the Selections map;
+       // - an identifier z in a variable declaration 'var z int'
+       //   is found only in the Defs map;
+       // - an identifier p denoting a package in a qualified
+       //   identifier p.X is found only in the Uses map.
+       //
+       // Similarly, no type is recorded for the (synthetic) FuncType
+       // node in a FuncDecl.Type field, since there is no corresponding
+       // syntactic function type expression in the source in this case
+       // Instead, the function type is found in the Defs.map entry for
+       // the corresponding function declaration.
        Types map[syntax.Expr]TypeAndValue
 
        // If StoreTypesInSyntax is set, type information identical to
index dea974bec80918ed9816e9e4c2690cde1d545868..beb2258c8b6f4793e3be21f34eee797eaac392dd 100644 (file)
@@ -217,11 +217,19 @@ type Info struct {
        //
        // The Types map does not record the type of every identifier,
        // only those that appear where an arbitrary expression is
-       // permitted. For instance, the identifier f in a selector
-       // expression x.f is found only in the Selections map, the
-       // identifier z in a variable declaration 'var z int' is found
-       // only in the Defs map, and identifiers denoting packages in
-       // qualified identifiers are collected in the Uses map.
+       // permitted. For instance:
+       // - an identifier f in a selector expression x.f is found
+       //   only in the Selections map;
+       // - an identifier z in a variable declaration 'var z int'
+       //   is found only in the Defs map;
+       // - an identifier p denoting a package in a qualified
+       //   identifier p.X is found only in the Uses map.
+       //
+       // Similarly, no type is recorded for the (synthetic) FuncType
+       // node in a FuncDecl.Type field, since there is no corresponding
+       // syntactic function type expression in the source in this case
+       // Instead, the function type is found in the Defs.map entry for
+       // the corresponding function declaration.
        Types map[ast.Expr]TypeAndValue
 
        // Instances maps identifiers denoting generic types or functions to their