| 1 | // Copyright 2026 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package ssa_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 9 | "go/astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/" |
| 10 | "go/importerscip-go gomod github.com/golang/go/src go1.25.0 `go/importer`/" |
| 11 | "go/parserscip-go gomod github.com/golang/go/src go1.25.0 `go/parser`/" |
| 12 | "go/tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/" |
| 13 | "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/" |
| 14 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 15 | |
| 16 | "golang.org/x/tools/go/ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/" |
| 17 | "golang.org/x/tools/internal/testenvscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testenv`/" |
| 18 | ) |
| 19 | |
| 20 | // generic |
| 21 | const gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g. = ` |
| 22 | package p |
| 23 | |
| 24 | type G[P any] struct { |
| 25 | x P |
| 26 | } |
| 27 | |
| 28 | func (g G[P]) M[Q any](q Q) (P, Q) { |
| 29 | return g.x, q |
| 30 | } |
| 31 | |
| 32 | func (g *G[P]) N[Q any](q Q) (P, Q) { |
| 33 | return g.x, q |
| 34 | } |
| 35 | |
| 36 | func f() { |
| 37 | g := G[int]{ x: 42 } |
| 38 | %s |
| 39 | } |
| 40 | ` |
| 41 | |
| 42 | // non-generic |
| 43 | const nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n. = ` |
| 44 | package p |
| 45 | |
| 46 | type N struct{} |
| 47 | |
| 48 | func (N) M[P any](p P) P { |
| 49 | return p |
| 50 | } |
| 51 | |
| 52 | func (*N) N[P any](p P) P { |
| 53 | return p |
| 54 | } |
| 55 | |
| 56 | func f() { |
| 57 | n := N{} |
| 58 | %s |
| 59 | } |
| 60 | ` |
| 61 | |
| 62 | // TestGenericMethods ensures that generic methods are properly instantiated. |
| 63 | func TestGenericMethodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/TestGenericMethods().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 64 | testenvscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testenv`/.NeedsGoCommand1Pointscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testenv`/NeedsGoCommand1Point().(t, 27) |
| 65 | |
| 66 | // TODO(mark): include implicit type arguments for direct callees? |
| 67 | // TODO(mark): ensure tpars == targs? |
| 68 | testCalls := []struct { |
| 69 | prog string |
| 70 | stmts string |
| 71 | callee string |
| 72 | tparams int // number of type parameters |
| 73 | targs int // number of type arguments |
| 74 | }{ |
| 75 | // value receivers on generic types |
| 76 | { |
| 77 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 78 | stmts: "g.M[bool](true)", |
| 79 | callee: "(p.G[int]).M[bool]", |
| 80 | tparams: 2, |
| 81 | targs: 2, |
| 82 | }, |
| 83 | { |
| 84 | // same as previous but with inferred type arguments |
| 85 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 86 | stmts: "g.M(true)", |
| 87 | callee: "(p.G[int]).M[bool]", |
| 88 | tparams: 2, |
| 89 | targs: 2, |
| 90 | }, |
| 91 | { |
| 92 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 93 | stmts: "f := g.M[bool]; f(true)", |
| 94 | callee: "(p.G[int]).M[bool]$bound", |
| 95 | tparams: 0, // not propagated |
| 96 | targs: 1, // receiver eagerly specialized |
| 97 | }, |
| 98 | { |
| 99 | // same as previous but with inferred type arguments |
| 100 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 101 | stmts: "var f func(bool) (int, bool); f = g.M; f(true)", |
| 102 | callee: "(p.G[int]).M[bool]$bound", |
| 103 | tparams: 0, |
| 104 | targs: 1, |
| 105 | }, |
| 106 | { |
| 107 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 108 | stmts: "f := G[int].M[bool]; f(g, true)", |
| 109 | callee: "(p.G[int]).M[bool]$thunk", |
| 110 | tparams: 0, // not propagated |
| 111 | targs: 1, // receiver eagerly specialized |
| 112 | }, |
| 113 | { |
| 114 | // same as previous but with inferred type arguments |
| 115 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 116 | stmts: "var f func(G[int], bool) (int, bool); f = (G[int]).M; f(g, true)", |
| 117 | callee: "(p.G[int]).M[bool]$thunk", |
| 118 | tparams: 0, |
| 119 | targs: 1, |
| 120 | }, |
| 121 | // pointer receivers on generic types |
| 122 | { |
| 123 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 124 | stmts: "g.N[bool](true)", |
| 125 | callee: "(*p.G[int]).N[bool]", |
| 126 | tparams: 2, |
| 127 | targs: 2, |
| 128 | }, |
| 129 | { |
| 130 | // same as previous but with inferred type arguments |
| 131 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 132 | stmts: "g.N(true)", |
| 133 | callee: "(*p.G[int]).N[bool]", |
| 134 | tparams: 2, |
| 135 | targs: 2, |
| 136 | }, |
| 137 | { |
| 138 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 139 | stmts: "f := g.N[bool]; f(true)", |
| 140 | callee: "(*p.G[int]).N[bool]$bound", |
| 141 | tparams: 0, // not propagated |
| 142 | targs: 1, // receiver eagerly specialized |
| 143 | }, |
| 144 | { |
| 145 | // same as previous but with inferred type arguments |
| 146 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 147 | stmts: "var f func(bool) (int, bool); f = g.N; f(true)", |
| 148 | callee: "(*p.G[int]).N[bool]$bound", |
| 149 | tparams: 0, |
| 150 | targs: 1, |
| 151 | }, |
| 152 | { |
| 153 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 154 | stmts: "f := (*G[int]).N[bool]; f(&g, true)", |
| 155 | callee: "(*p.G[int]).N[bool]$thunk", |
| 156 | tparams: 0, // not propagated |
| 157 | targs: 1, // receiver eagerly specialized |
| 158 | }, |
| 159 | { |
| 160 | // same as previous but with inferred type arguments |
| 161 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 162 | stmts: "var f func(*G[int], bool) (int, bool); f = (*G[int]).N[bool]; f(&g, true)", |
| 163 | callee: "(*p.G[int]).N[bool]$thunk", |
| 164 | tparams: 0, |
| 165 | targs: 1, |
| 166 | }, |
| 167 | // value receivers on non-generic types |
| 168 | { |
| 169 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 170 | stmts: "n.M[bool](true)", |
| 171 | callee: "(p.N).M[bool]", |
| 172 | tparams: 1, |
| 173 | targs: 1, |
| 174 | }, |
| 175 | { |
| 176 | // same as previous but with inferred type arguments |
| 177 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 178 | stmts: "n.M(true)", |
| 179 | callee: "(p.N).M[bool]", |
| 180 | tparams: 1, |
| 181 | targs: 1, |
| 182 | }, |
| 183 | { |
| 184 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 185 | stmts: "f := n.M[bool]; f(true)", |
| 186 | callee: "(p.N).M[bool]$bound", |
| 187 | tparams: 0, // not propagated |
| 188 | targs: 1, |
| 189 | }, |
| 190 | { |
| 191 | // same as previous but with inferred type arguments |
| 192 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 193 | stmts: "var f func(bool) bool; f = n.M; f(true)", |
| 194 | callee: "(p.N).M[bool]$bound", |
| 195 | tparams: 0, |
| 196 | targs: 1, |
| 197 | }, |
| 198 | { |
| 199 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 200 | stmts: "f := N.M[bool]; f(n, true)", |
| 201 | callee: "(p.N).M[bool]$thunk", |
| 202 | tparams: 0, // not propagated |
| 203 | targs: 1, |
| 204 | }, |
| 205 | { |
| 206 | // same as previous but with inferred type arguments |
| 207 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 208 | stmts: "var f func(N, bool) bool; f = N.M; f(n, true)", |
| 209 | callee: "(p.N).M[bool]$thunk", |
| 210 | tparams: 0, |
| 211 | targs: 1, |
| 212 | }, |
| 213 | // pointer receivers on non-generic types |
| 214 | { |
| 215 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 216 | stmts: "n.N[bool](true)", |
| 217 | callee: "(*p.N).N[bool]", |
| 218 | tparams: 1, |
| 219 | targs: 1, |
| 220 | }, |
| 221 | { |
| 222 | // same as previous but with inferred type arguments |
| 223 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 224 | stmts: "n.N(true)", |
| 225 | callee: "(*p.N).N[bool]", |
| 226 | tparams: 1, |
| 227 | targs: 1, |
| 228 | }, |
| 229 | { |
| 230 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 231 | stmts: "f := n.N[bool]; f(true)", |
| 232 | callee: "(*p.N).N[bool]$bound", |
| 233 | tparams: 0, // not propagated |
| 234 | targs: 1, |
| 235 | }, |
| 236 | { |
| 237 | // same as previous but with inferred type arguments |
| 238 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 239 | stmts: "var f func(bool) bool; f = n.N[bool]; f(true)", |
| 240 | callee: "(*p.N).N[bool]$bound", |
| 241 | tparams: 0, |
| 242 | targs: 1, |
| 243 | }, |
| 244 | { |
| 245 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 246 | stmts: "f := (*N).N[bool]; f(&n, true)", |
| 247 | callee: "(*p.N).N[bool]$thunk", |
| 248 | tparams: 0, // not propagated |
| 249 | targs: 1, |
| 250 | }, |
| 251 | { |
| 252 | // same as previous but with inferred type arguments |
| 253 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 254 | stmts: "var f func(*N, bool) bool; f = (*N).N; f(&n, true)", |
| 255 | callee: "(*p.N).N[bool]$thunk", |
| 256 | tparams: 0, |
| 257 | targs: 1, |
| 258 | }, |
| 259 | // bounds of instantiated signatures which only differ by receiver pointerness |
| 260 | { |
| 261 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 262 | stmts: "f := g.M[bool]; _ = g.N[bool]; f(true)", |
| 263 | callee: "(p.G[int]).M[bool]$bound", |
| 264 | tparams: 0, // not propagated |
| 265 | targs: 1, // receiver eagerly specialized |
| 266 | }, |
| 267 | { |
| 268 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 269 | stmts: "_ = g.M[bool]; f := g.N[bool]; f(true)", |
| 270 | callee: "(*p.G[int]).N[bool]$bound", |
| 271 | tparams: 0, // not propagated |
| 272 | targs: 1, // receiver eagerly specialized |
| 273 | }, |
| 274 | { |
| 275 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 276 | stmts: "f := n.M[bool]; _ = n.N[bool]; f(true)", |
| 277 | callee: "(p.N).M[bool]$bound", |
| 278 | tparams: 0, // not propagated |
| 279 | targs: 1, |
| 280 | }, |
| 281 | { |
| 282 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 283 | stmts: "_ = n.M[bool]; f := n.N[bool]; f(true)", |
| 284 | callee: "(*p.N).N[bool]$bound", |
| 285 | tparams: 0, // not propagated |
| 286 | targs: 1, |
| 287 | }, |
| 288 | // thunks of instantiated signatures which only differ by receiver pointerness |
| 289 | { |
| 290 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 291 | stmts: "f := G[int].M[bool]; _ = (*G[int]).N[bool]; f(g, true)", |
| 292 | callee: "(p.G[int]).M[bool]$thunk", |
| 293 | tparams: 0, // not propagated |
| 294 | targs: 1, // receiver eagerly specialized |
| 295 | }, |
| 296 | { |
| 297 | prog: gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., |
| 298 | stmts: "_ = G[int].M[bool]; f := (*G[int]).N[bool]; f(&g, true)", |
| 299 | callee: "(*p.G[int]).N[bool]$thunk", |
| 300 | tparams: 0, // not propagated |
| 301 | targs: 1, // receiver eagerly specialized |
| 302 | }, |
| 303 | { |
| 304 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 305 | stmts: "f := N.M[bool]; _ = (*N).N[bool]; f(n, true)", |
| 306 | callee: "(p.N).M[bool]$thunk", |
| 307 | tparams: 0, // not propagated |
| 308 | targs: 1, |
| 309 | }, |
| 310 | { |
| 311 | prog: nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., |
| 312 | stmts: "_ = N.M[bool]; f := (*N).N[bool]; f(&n, true)", |
| 313 | callee: "(*p.N).N[bool]$thunk", |
| 314 | tparams: 0, |
| 315 | targs: 1, |
| 316 | }, |
| 317 | } |
| 318 | |
| 319 | for _, want := range testCalls { |
| 320 | prog := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(want.prog, want.stmts) |
| 321 | calls := getCallsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/getCalls().(t, buildscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/build().(t, prog)) |
| 322 | |
| 323 | if len(calls) != 1 { |
| 324 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("too many direct calls for %s: got %d, want 1", prog, len(calls)) |
| 325 | } |
| 326 | |
| 327 | got := calls[0] |
| 328 | if got.calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#callee. != want.callee { |
| 329 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("wrong callee for %s: got %s, want %s", prog, got.calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#callee., want.callee) |
| 330 | } |
| 331 | if got.tparamsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#tparams. != want.tparams { |
| 332 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("wrong number of tparams for %s: got %d, want %d", prog, got.tparamsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#tparams., want.tparams) |
| 333 | } |
| 334 | if got.targsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#targs. != want.targs { |
| 335 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("wrong number of targs for %s: got %d, want %d", prog, got.targsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#targs., want.targs) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | testBuilds := []string{ |
| 340 | // instantiate same signature with value / pointer receivers |
| 341 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(gscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/g., "_ = g.M[bool]; _ = g.N[bool]"), |
| 342 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/n., "_ = n.M[bool]; _ = n.N[bool]"), |
| 343 | } |
| 344 | |
| 345 | for _, prog := range testBuilds { |
| 346 | buildscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/build().(t, prog) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | type callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call# struct { |
| 351 | calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#callee. string |
| 352 | tparamsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#tparams. int |
| 353 | targsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#targs. int |
| 354 | } |
| 355 | |
| 356 | func buildscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/build().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, src string) *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Packagescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Package# { |
| 357 | fset := tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.NewFileSetscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/NewFileSet().() |
| 358 | f, err := parserscip-go gomod github.com/golang/go/src go1.25.0 `go/parser`/.ParseFilescip-go gomod github.com/golang/go/src go1.25.0 `go/parser`/ParseFile().(fset, "p.go", src, 0) |
| 359 | if err != nil { |
| 360 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 361 | } |
| 362 | |
| 363 | conf := typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Config#{Importerscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Config#Importer.: importerscip-go gomod github.com/golang/go/src go1.25.0 `go/importer`/.Defaultscip-go gomod github.com/golang/go/src go1.25.0 `go/importer`/Default().()} |
| 364 | info := &typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Infoscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#{ |
| 365 | Typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Types.: make(map[astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Exprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Expr#]typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.TypeAndValuescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/TypeAndValue#), |
| 366 | Defsscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Defs.: make(map[*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#]typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Objectscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Object#), |
| 367 | Usesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Uses.: make(map[*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#]typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Objectscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Object#), |
| 368 | Selectionsscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Selections.: make(map[*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.SelectorExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/SelectorExpr#]*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Selectionscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Selection#), |
| 369 | Instancesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Instances.: make(map[*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#]typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Instancescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Instance#), |
| 370 | } |
| 371 | pkg, err := conf.Checkscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Config#Check().("p", fset, []*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Filescip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/File#{f}, info) |
| 372 | if err != nil { |
| 373 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 374 | } |
| 375 | |
| 376 | prog := ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.NewProgramscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/NewProgram().(fset, ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.SanityCheckFunctionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/SanityCheckFunctions.|ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.InstantiateGenericsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/InstantiateGenerics.) |
| 377 | p := prog.CreatePackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Program#CreatePackage().(pkg, []*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Filescip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/File#{f}, info, true) |
| 378 | prog.Buildscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Program#Build().() |
| 379 | |
| 380 | return p |
| 381 | } |
| 382 | |
| 383 | func getCallsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/getCalls().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, p *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Packagescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Package#) []*callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call# { |
| 384 | fun := p.Funcscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Package#Func().("f") |
| 385 | if fun == nil { |
| 386 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("f not found") |
| 387 | } |
| 388 | |
| 389 | var calls []*callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call# |
| 390 | for _, block := range fun.Blocksscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#Blocks. { |
| 391 | for _, instr := range block.Instrsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/BasicBlock#Instrs. { |
| 392 | if c, ok := instr.(*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Call#); ok { |
| 393 | fn := c.Callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Call#Call..StaticCalleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/CallCommon#StaticCallee().() |
| 394 | calls = append(calls, &callscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#{ |
| 395 | calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#callee.: fn.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#String().(), |
| 396 | tparamsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#tparams.: fn.TypeParamsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#TypeParams().().Lenscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/TypeParamList#Len().(), |
| 397 | targsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa_test`/call#targs.: len(fn.TypeArgsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#TypeArgs().()), |
| 398 | }) |
| 399 | } |
| 400 | // don't care about the extra call for MakeClosure |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return calls |
| 405 | } |