@@ -518,6 +518,7 @@ func extractMethod(tw *trap.Writer, meth *types.Func) trap.Label {
518
518
// For more information on objects, see:
519
519
// https://github.com/golang/example/blob/master/gotypes/README.md#objects
520
520
func extractObject (tw * trap.Writer , obj types.Object , lbl trap.Label ) {
521
+ checkObjectNotSpecialized (obj )
521
522
name := obj .Name ()
522
523
isBuiltin := obj .Parent () == types .Universe
523
524
var kind int
@@ -1607,7 +1608,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1607
1608
case * types.Struct :
1608
1609
kind = dbscheme .StructType .Index ()
1609
1610
for i := 0 ; i < tp .NumFields (); i ++ {
1610
- field := tp .Field (i )
1611
+ field := tp .Field (i ). Origin ()
1611
1612
1612
1613
// ensure the field is associated with a label - note that
1613
1614
// struct fields do not have a parent scope, so they are not
@@ -1637,7 +1638,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1637
1638
// Note that methods coming from embedded interfaces can be
1638
1639
// accessed through `Method(i)`, so there is no need to
1639
1640
// deal with them separately.
1640
- meth := tp .Method (i )
1641
+ meth := tp .Method (i ). Origin ()
1641
1642
1642
1643
// Note that methods do not have a parent scope, so they are
1643
1644
// not dealt with by `extractScopes`
@@ -1707,15 +1708,15 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1707
1708
// ensure all methods have labels - note that methods do not have a
1708
1709
// parent scope, so they are not dealt with by `extractScopes`
1709
1710
for i := 0 ; i < origintp .NumMethods (); i ++ {
1710
- meth := origintp .Method (i )
1711
+ meth := origintp .Method (i ). Origin ()
1711
1712
1712
1713
extractMethod (tw , meth )
1713
1714
}
1714
1715
1715
1716
// associate all methods of underlying interface with this type
1716
1717
if underlyingInterface , ok := underlying .(* types.Interface ); ok {
1717
1718
for i := 0 ; i < underlyingInterface .NumMethods (); i ++ {
1718
- methlbl := extractMethod (tw , underlyingInterface .Method (i ))
1719
+ methlbl := extractMethod (tw , underlyingInterface .Method (i ). Origin () )
1719
1720
dbscheme .MethodHostsTable .Emit (tw , methlbl , lbl )
1720
1721
}
1721
1722
}
@@ -1787,7 +1788,7 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
1787
1788
case * types.Interface :
1788
1789
var b strings.Builder
1789
1790
for i := 0 ; i < tp .NumMethods (); i ++ {
1790
- meth := tp .Method (i )
1791
+ meth := tp .Method (i ). Origin ()
1791
1792
methLbl := extractType (tw , meth .Type ())
1792
1793
if i > 0 {
1793
1794
b .WriteString ("," )
@@ -2143,3 +2144,20 @@ func skipExtractingValueForLeftOperand(tw *trap.Writer, be *ast.BinaryExpr) bool
2143
2144
}
2144
2145
return true
2145
2146
}
2147
+
2148
+ // checkObjectNotSpecialized exits the program if `obj` is specialized. Note
2149
+ // that specialization is only possible for function objects and variable
2150
+ // objects.
2151
+ func checkObjectNotSpecialized (obj types.Object ) {
2152
+ if funcObj , ok := obj .(* types.Func ); ok && funcObj != funcObj .Origin () {
2153
+ log .Fatalf ("Encountered unexpected specialization %s of generic function object %s" , funcObj .FullName (), funcObj .Origin ().FullName ())
2154
+ }
2155
+ if varObj , ok := obj .(* types.Var ); ok && varObj != varObj .Origin () {
2156
+ log .Fatalf ("Encountered unexpected specialization %s of generic variable object %s" , varObj .String (), varObj .Origin ().String ())
2157
+ }
2158
+ if typeNameObj , ok := obj .(* types.TypeName ); ok {
2159
+ if namedType , ok := typeNameObj .Type ().(* types.Named ); ok && namedType != namedType .Origin () {
2160
+ log .Fatalf ("Encountered type object for specialization %s of named type %s" , namedType .String (), namedType .Origin ().String ())
2161
+ }
2162
+ }
2163
+ }
0 commit comments