collectSubtypeConsts scans a *types.Package for exported constants of type errs.Subtype whose name starts with "Subtype" and records them by name. The "Subtype" name prefix is enforced so the helper aligns with the CheckDeclaredSubtype AST pass and avoids matching the underlying `Subtype` type defin
(pkg *types.Package, into map[string]*types.Const)
| 119 | // the CheckDeclaredSubtype AST pass and avoids matching the underlying `Subtype` type |
| 120 | // definition itself. |
| 121 | func collectSubtypeConsts(pkg *types.Package, into map[string]*types.Const) { |
| 122 | if pkg == nil || pkg.Scope() == nil { |
| 123 | return |
| 124 | } |
| 125 | for _, name := range pkg.Scope().Names() { |
| 126 | if !strings.HasPrefix(name, "Subtype") || name == "Subtype" { |
| 127 | continue |
| 128 | } |
| 129 | obj := pkg.Scope().Lookup(name) |
| 130 | c, ok := obj.(*types.Const) |
| 131 | if !ok { |
| 132 | continue |
| 133 | } |
| 134 | // Verify the constant's type is errs.Subtype (not e.g. a foreign |
| 135 | // "Subtype"-named string alias re-exported from this package). |
| 136 | named, ok := c.Type().(*types.Named) |
| 137 | if !ok { |
| 138 | continue |
| 139 | } |
| 140 | if named.Obj() == nil || named.Obj().Name() != "Subtype" || |
| 141 | named.Obj().Pkg() == nil || named.Obj().Pkg().Path() != errsPkgPath { |
| 142 | continue |
| 143 | } |
| 144 | into[name] = c |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // ResolveSubtypeIdent inspects the identifier used as the value of a |
| 149 | // `Subtype:` composite-literal field and reports the typed-scope verdict |