Skip to content

Commit

Permalink
Update extractor to deal with type parameters on alias types
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-mc committed Jan 9, 2025
1 parent 77858c3 commit 99322d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions go/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ func extractObjects(tw *trap.Writer, scope *types.Scope, scopeLabel trap.Label)
populateTypeParamParents(funcObj.Type().(*types.Signature).TypeParams(), obj)
populateTypeParamParents(funcObj.Type().(*types.Signature).RecvTypeParams(), obj)
}
// Populate type parameter parents for named types. Note that we
// skip type aliases as the original type should be the parent
// of any type parameters.
if typeNameObj, ok := obj.(*types.TypeName); ok && !typeNameObj.IsAlias() {
// Populate type parameter parents for named types.
if typeNameObj, ok := obj.(*types.TypeName); ok {
if tp, ok := typeNameObj.Type().(*types.Named); ok {
populateTypeParamParents(tp.TypeParams(), obj)
} else if tp, ok := typeNameObj.Type().(*types.Alias); ok {
populateTypeParamParents(tp.TypeParams(), obj)
}
}
extractObject(tw, obj, lbl)
Expand Down
5 changes: 5 additions & 0 deletions go/ql/test/library-tests/semmle/go/Types/Aliases.expected
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ entities
| aliases.go | aliases.go:22:6:22:6 | T | 1 | aliases.go:19:6:19:7 | S3 |
| aliases.go | aliases.go:25:6:25:6 | H | 1 | file://:0:0:0:0 | signature type |
| aliases.go | aliases.go:25:8:25:11 | Afs3 | 1 | aliases.go:19:6:19:7 | S3 |
| aliases.go | aliases.go:29:6:29:9 | User | 1 | aliases.go:29:6:29:9 | User |
| aliases.go | aliases.go:29:11:29:15 | UserT | 1 | file://:0:0:0:0 | type parameter type |
| aliases.go | aliases.go:29:30:29:30 | x | 1 | file://:0:0:0:0 | type parameter type |
| aliases.go | aliases.go:32:6:32:14 | UserAlias | 1 | aliases.go:29:6:29:9 | User |
| aliases.go | aliases.go:32:16:32:25 | UserAliasT | 1 | file://:0:0:0:0 | type parameter type |
#select
| F | func(struct { x int }) int |
| G | func(struct { x int }) int |
Expand Down

0 comments on commit 99322d5

Please sign in to comment.