@@ -363,10 +363,14 @@ func extractObjects(tw *trap.Writer, scope *types.Scope, scopeLabel trap.Label)
363
363
obj := scope .Lookup (name )
364
364
lbl , exists := tw .Labeler .ScopedObjectID (obj , func () trap.Label { return extractType (tw , obj .Type ()) })
365
365
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.
366
369
if funcObj , ok := obj .(* types.Func ); ok {
367
370
populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).TypeParams (), lbl )
368
371
populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).RecvTypeParams (), lbl )
369
372
}
373
+ // Populate type parameter parents for named types.
370
374
if typeNameObj , ok := obj .(* types.TypeName ); ok {
371
375
if tp , ok := typeNameObj .Type ().(* types.Named ); ok {
372
376
populateTypeParamParents (tw , tp .TypeParams (), lbl )
@@ -393,6 +397,8 @@ func extractMethod(tw *trap.Writer, meth *types.Func) trap.Label {
393
397
// if the method label does not exist, extract it
394
398
methlbl , exists := tw .Labeler .MethodID (meth , recvtyplbl )
395
399
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.
396
402
populateTypeParamParents (tw , meth .Type ().(* types.Signature ).TypeParams (), methlbl )
397
403
populateTypeParamParents (tw , meth .Type ().(* types.Signature ).RecvTypeParams (), methlbl )
398
404
extractObject (tw , meth , methlbl )
@@ -994,8 +1000,7 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int) {
994
1000
_ , isUnionType := typeOf (tw , expr ).(* types.Union )
995
1001
if expr .Op == token .OR && isUnionType {
996
1002
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 )
999
1004
} else {
1000
1005
tp := dbscheme .BinaryExprs [expr .Op ]
1001
1006
if tp == nil {
@@ -1033,7 +1038,7 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int) {
1033
1038
kind = dbscheme .InterfaceTypeExpr .Index ()
1034
1039
// expr.Methods contains methods, embedded interfaces and type set
1035
1040
// literals.
1036
- overrideTypesOfTypeSetLiterals (tw , expr .Methods )
1041
+ makeTypeSetLiteralsUnionTyped (tw , expr .Methods )
1037
1042
extractFields (tw , expr .Methods , lbl , 0 , 1 )
1038
1043
case * ast.MapType :
1039
1044
if expr == nil {
@@ -1813,8 +1818,9 @@ func createUnionFromType(t types.Type) *types.Union {
1813
1818
1814
1819
// Go through a `FieldList` and update the types of all type set literals which
1815
1820
// 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 ) {
1818
1824
if fields == nil || fields .List == nil {
1819
1825
return
1820
1826
}
@@ -1853,7 +1859,9 @@ func extractTypeParamDecls(tw *trap.Writer, fields *ast.FieldList, parent trap.L
1853
1859
return
1854
1860
}
1855
1861
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 )
1857
1865
1858
1866
idx := 0
1859
1867
for _ , field := range fields .List {
0 commit comments