8000 Address review comments 1 · github/codeql-go@9abc7ea · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 9abc7ea

Browse files
owen-mcsmowton
authored andcommitted
Address review comments 1
1 parent 4828430 commit 9abc7ea

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

extractor/dbscheme/tables.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,20 @@ var ParenExpr = ExprKind.NewBranch("@parenexpr")
379379
var SelectorExpr = ExprKind.NewBranch("@selectorexpr")
380380

381381
// IndexExpr is the type of AST nodes for index expressions and generic type
382-
// instantiation expressions with one type argument
382+
// instantiation expressions with one type argument. Note that syntactically
383+
// unambiguous generic instantiations will be extracted as
384+
// `GenericTypeInstantiationExpr`.
383385
var IndexExpr = ExprKind.NewBranch("@indexexpr")
384386

385-
// GenericFunctionInstantiationExpr is the type of AST nodes that represent a instantiation
387+
// GenericFunctionInstantiationExpr is the type of AST nodes that represent an instantiation
386388
// of a generic type. These correspond to some index expression AST nodes and all index
387389
// list expression AST nodes.
388390
var GenericFunctionInstantiationExpr = ExprKind.NewBranch("@genericfunctioninstantiationexpr")
389391

390392
// GenericTypeInstantiationExpr is the type of AST nodes that represent an instantiation
391393
// of a generic type. These correspond to some index expression AST nodes and all index
392-
// list expression AST nodes.
394+
// list expression AST nodes. Note some syntactically ambiguous instantations are
395+
// extracted as an `IndexExpr` to be disambiguated in QL later.
393396
var GenericTypeInstantiationExpr = ExprKind.NewBranch("@generictypeinstantiationexpr")
394397

395398
// SliceExpr is the type of slice expression AST nodes

extractor/extractor.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,14 @@ func extractObjects(tw *trap.Writer, scope *types.Scope, scopeLabel trap.Label)
363363
obj := scope.Lookup(name)
364364
lbl, exists := tw.Labeler.ScopedObjectID(obj, func() trap.Label { return extractType(tw, obj.Type()) })
365365
if !exists {
366+
// Populate type parameter parents for functions. Note that methods
367+
// do not appear as objects in any scope, so they have to be dealt
368+
// with separately in extractMethods.
366369
if funcObj, ok := obj.(*types.Func); ok {
367370
populateTypeParamParents(tw, funcObj.Type().(*types.Signature).TypeParams(), lbl)
368371
populateTypeParamParents(tw, funcObj.Type().(*types.Signature).RecvTypeParams(), lbl)
369372
}
373+
// Populate type parameter parents for named types.
370374
if typeNameObj, ok := obj.(*types.TypeName); ok {
371375
if tp, ok := typeNameObj.Type().(*types.Named); ok {
372376
populateTypeParamParents(tw, tp.TypeParams(), lbl)
@@ -393,6 +397,8 @@ func extractMethod(tw *trap.Writer, meth *types.Func) trap.Label {
393397
// if the method label does not exist, extract it
394398
methlbl, exists := tw.Labeler.MethodID(meth, recvtyplbl)
395399
if !exists {
400+
// Populate type parameter parents for methods. They do not appear as
401+
// objects in any scope, so they have to be dealt with separately here.
396402
populateTypeParamParents(tw, meth.Type().(*types.Signature).TypeParams(), methlbl)
397403
populateTypeParamParents(tw, meth.Type().(*types.Signature).RecvTypeParams(), methlbl)
398404
extractObject(tw, meth, methlbl)
@@ -994,8 +1000,7 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int) {
9941000
_, isUnionType := typeOf(tw, expr).(*types.Union)
9951001
if expr.Op == token.OR && isUnionType {
9961002
kind = dbscheme.TypeSetLiteralExpr.Index()
997-
n := flattenBinaryExprTree(tw, expr.X, lbl, 0)
998-
flattenBinaryExprTree(tw, expr.Y, lbl, n)
1003+
flattenBinaryExprTree(tw, expr, lbl, 0)
9991004
} else {
10001005
tp := dbscheme.BinaryExprs[expr.Op]
10011006
if tp == nil {
@@ -1033,7 +1038,7 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int) {
10331038
kind = dbscheme.InterfaceTypeExpr.Index()
10341039
// expr.Methods contains methods, embedded interfaces and type set
10351040
// literals.
1036-
overrideTypesOfTypeSetLiterals(tw, expr.Methods)
1041+
makeTypeSetLiteralsUnionTyped(tw, expr.Methods)
10371042
extractFields(tw, expr.Methods, lbl, 0, 1)
10381043
case *ast.MapType:
10391044
if expr == nil {
@@ -1813,8 +1818,9 @@ func createUnionFromType(t types.Type) *types.Union {
18131818

18141819
// Go through a `FieldList` and update the types of all type set literals which
18151820
// are not already union types to be union types. We do this by changing the
1816-
// types stored in `tw.Package.TypesInfo.Types`.
1817-
func overrideTypesOfTypeSetLiterals(tw *trap.Writer, fields *ast.FieldList) {
1821+
// types stored in `tw.Package.TypesInfo.Types`. Type set literals can only
1822+
// occur in two places: a type parameter declaration or a type in an interface.
1823+
func makeTypeSetLiteralsUnionTyped(tw *trap.Writer, fields *ast.FieldList) {
18181824
if fields == nil || fields.List == nil {
18191825
return
18201826
}
@@ -1853,7 +1859,9 @@ func extractTypeParamDecls(tw *trap.Writer, fields *ast.FieldList, parent trap.L
18531859
return
18541860
}
18551861

1856-
overrideTypesOfTypeSetLiterals(tw, fields)
1862+
// Type set literals can occur as the type in a type parameter declaration,
1863+
// so we ensure that they are union typed.
1864+
makeTypeSetLiteralsUnionTyped(tw, fields)
18571865

18581866
idx := 0
18591867
for _, field := range fields.List {

0 commit comments

Comments
 (0)
0