# go — CWE-407 Diamond Recursion Scan — CLEAN

Scanned: `src/cmd/compile/internal/types2/` and `src/go/types/`

## Functions Examined

| Function | File | Guard | Verdict |
|----------|------|-------|---------|
| `computeInterfaceTypeSet` | typeset.go | `ityp.tset != nil` + sets sentinel before recursing | CLEAN |
| `comparableType` | predicates.go | `if seen[T] { return nil }` before `seen[T] = true` | CLEAN |
| `hasInvalidEmbeddedFields` | lookup.go | `if S != nil && !seen[S]` before `seen[S] = true` | CLEAN |
| `tpWalker.isParameterized` | infer.go | `if x, ok := w.seen[typ]; ok { return x }` before set | CLEAN |
| `cycleFinder.typ` | infer.go | `if w.seen[typ] { return }` before `w.seen[typ] = true` | CLEAN |
| `findPath` | initorder.go | `if seen[from] { return nil }` before `seen[from] = true` | CLEAN |
| `lookupFieldOrMethodImpl` | lookup.go | BFS with `instanceLookup` dedup | CLEAN |
| `typestring writer` | typestring.go | `if w.seen[typ] { return }` before `w.seen[typ] = true` | CLEAN |

## Note

`go/types` is auto-generated from `cmd/compile/internal/types2` — same source, same protections.

`validType0` uses a `nest []*Named` slice for cycle detection (O(D) linear scan per node), not
a hash set — this is O(D²) in the worst case but does NOT produce exponential re-traversal on
diamond hierarchies because Go's named-type graph is a DAG of declared types.  Spurious
re-visitation via the slice is bounded by path length, not by the exponential fanout of a diamond.

**Scan verdict: CLEAN — no CWE-407 diamond recursion defects found.**
