Skip to content

Commit a810309

Browse files
committed
Add check for specialized objects
1 parent 45710e2 commit a810309

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

go/extractor/extractor.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ func extractMethod(tw *trap.Writer, meth *types.Func) trap.Label {
518518
// For more information on objects, see:
519519
// https://github.com/golang/example/blob/master/gotypes/README.md#objects
520520
func extractObject(tw *trap.Writer, obj types.Object, lbl trap.Label) {
521+
checkObjectNotSpecialized(obj)
521522
name := obj.Name()
522523
isBuiltin := obj.Parent() == types.Universe
523524
var kind int
@@ -2143,3 +2144,15 @@ func skipExtractingValueForLeftOperand(tw *trap.Writer, be *ast.BinaryExpr) bool
21432144
}
21442145
return true
21452146
}
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+
}

0 commit comments

Comments
 (0)