mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Use Origin()
This commit is contained in:
@@ -1946,71 +1946,6 @@ func populateTypeParamParents(tw *trap.Writer, typeparams *types.TypeParamList,
|
||||
// some changes to the object to avoid returning objects relating to instantiated
|
||||
// types.
|
||||
func getObjectBeingUsed(tw *trap.Writer, ident *ast.Ident) types.Object {
|
||||
obj1 := getObjectBeingUsed1(tw, ident)
|
||||
obj2 := getObjectBeingUsed2(tw, ident)
|
||||
if obj1 != obj2 {
|
||||
string1 := "nil"
|
||||
if obj1 != nil {
|
||||
string1 = obj1.String()
|
||||
}
|
||||
string2 := "nil"
|
||||
if obj1 != nil {
|
||||
string2 = obj1.String()
|
||||
}
|
||||
log.Fatalf("different results!\nobj1 = %s\nobj2 = %s\n", string1, string2)
|
||||
}
|
||||
return obj2
|
||||
}
|
||||
|
||||
// getobjectBeingUsed looks up `ident` in `tw.Package.TypesInfo.Uses` and makes
|
||||
// some changes to the object to avoid returning objects relating to instantiated
|
||||
// types.
|
||||
func getObjectBeingUsed1(tw *trap.Writer, ident *ast.Ident) types.Object {
|
||||
obj := tw.Package.TypesInfo.Uses[ident]
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
if override, ok := tw.ObjectsOverride[obj]; ok {
|
||||
return override
|
||||
}
|
||||
if funcObj, ok := obj.(*types.Func); ok {
|
||||
sig := funcObj.Type().(*types.Signature)
|
||||
if recv := sig.Recv(); recv != nil {
|
||||
recvType := recv.Type()
|
||||
originType, isSame := tryGetGenericType(recvType)
|
||||
|
||||
if originType == nil {
|
||||
if pointerType, ok := recvType.(*types.Pointer); ok {
|
||||
originType, isSame = tryGetGenericType(pointerType.Elem())
|
||||
}
|
||||
}
|
||||
|
||||
if originType == nil || isSame {
|
||||
return obj
|
||||
}
|
||||
|
||||
for i := 0; i < originType.NumMethods(); i++ {
|
||||
meth := originType.Method(i)
|
||||
if meth.Name() == funcObj.Name() {
|
||||
return meth
|
||||
}
|
||||
}
|
||||
if interfaceType, ok := originType.Underlying().(*types.Interface); ok {
|
||||
for i := 0; i < interfaceType.NumMethods(); i++ {
|
||||
meth := interfaceType.Method(i)
|
||||
if meth.Name() == funcObj.Name() {
|
||||
return meth
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Fatalf("Could not find method %s on type %s", funcObj.Name(), originType)
|
||||
}
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
func getObjectBeingUsed2(tw *trap.Writer, ident *ast.Ident) types.Object {
|
||||
switch obj := tw.Package.TypesInfo.Uses[ident].(type) {
|
||||
case *types.Var:
|
||||
return obj.Origin()
|
||||
|
||||
Reference in New Issue
Block a user