`Has unexported methods`,
},
},
+ // Interface with comparable constraint.
+ {
+ "interface type with comparable",
+ []string{p, `ExportedComparableInterface`},
+ []string{
+ `Comment about exported interface with comparable`, // Include comment.
+ `type ExportedComparableInterface interface`, // Interface definition.
+ `comparable.*Comment on line with comparable`, // Comparable should be shown.
+ `ExportedMethod\(\).*Comment on line with exported method`,
+ `Has unexported methods`,
+ },
+ []string{
+ `unexportedMethod`, // No unexported method.
+ },
+ },
+ // Interface with only comparable (no unexported methods).
+ {
+ "interface type with comparable only",
+ []string{p, `ExportedComparableOnlyInterface`},
+ []string{
+ `ExportedComparableOnlyInterface has only comparable`, // Include comment.
+ `type ExportedComparableOnlyInterface interface`, // Interface definition.
+ `comparable.*Comment on line with comparable`, // Comparable should be shown.
+ `ExportedMethod\(\).*Comment on line with exported method`,
+ },
+ []string{
+ `Has unexported methods`, // Should NOT appear - no unexported methods.
+ },
+ },
// Interface method.
{
constraint := false
switch ident := ty.(type) {
case *ast.Ident:
- if isInterface && ident.Name == "error" && ident.Obj == nil {
+ if isInterface && ident.Obj == nil &&
+ (ident.Name == "error" || ident.Name == "comparable") {
// For documentation purposes, we consider the builtin error
- // type special when embedded in an interface, such that it
- // always gets shown publicly.
+ // and comparable types special when embedded in an interface,
+ // such that they always get shown publicly.
list = append(list, field)
continue
}
type StructConstraint interface {
struct { F int }
}
+
+// Comment about exported interface with comparable.
+type ExportedComparableInterface interface {
+ comparable // Comment on line with comparable.
+ ExportedMethod() // Comment on line with exported method.
+ unexportedMethod() // Comment on line with unexported method.
+}
+
+// ExportedComparableOnlyInterface has only comparable and exported method (no unexported).
+type ExportedComparableOnlyInterface interface {
+ comparable // Comment on line with comparable.
+ ExportedMethod() // Comment on line with exported method.
+}