golang.org/x/tools/gopls@v0.15.3/internal/golang/origin.go (about)

     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  //go:build !go1.19
     6  // +build !go1.19
     7  
     8  package golang
     9  
    10  import "go/types"
    11  
    12  // containsOrigin reports whether the provided object set contains an object
    13  // with the same origin as the provided obj (which may be a synthetic object
    14  // created during instantiation).
    15  func containsOrigin(objSet map[types.Object]bool, obj types.Object) bool {
    16  	if obj == nil {
    17  		return objSet[obj]
    18  	}
    19  	// In Go 1.18, we can't use the types.Var.Origin and types.Func.Origin methods.
    20  	for target := range objSet {
    21  		if target.Pkg() == obj.Pkg() && target.Pos() == obj.Pos() && target.Name() == obj.Name() {
    22  			return true
    23  		}
    24  	}
    25  	return false
    26  }