Debian Codegraph @

gopls/internal/golang/origin.go

raw symbols SCIP
1 // Copyright 2023 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 golang
6
7 import "go/types"
8
9 // containsOrigin reports whether the provided object set contains an object
10 // with the same origin as the provided obj (which may be a synthetic object
11 // created during instantiation).
12 func containsOrigin(objSet map[types.Object]bool, obj types.Object) bool {
13 if objSet[obj] {
14 return true // fast path: exact match (common for non-generic code)
15 }
16 objOrigin := origin(obj)
17 if objOrigin == obj {
18 return false // non-generic: origin is identity, so no match
19 }
20 for target := range objSet {
21 if origin(target) == objOrigin {
22 return true
23 }
24 }
25 return false
26 }
27
28 func origin(obj types.Object) types.Object {
29 switch obj := obj.(type) {
30 case *types.Var:
31 return obj.Origin()
32 case *types.Func:
33 return obj.Origin()
34 }
35 return obj
36 }