Skip to content

Can't return an interface #7582

@shykes

Description

@shykes

The interface documentation shows how to define an interface and use it in arguments. But it doesn't show how to use the interface in the return value. I tried, but it doesn't seem to be possible.

It would be very useful to make this possible.

Example:

type Check interface {
 Pass() bool
 Details() string
}
 
type MyCheck struct {}
 
func (c *MyCheck) Pass() bool {
  return true
}
 
func (c *MyCheck) Details() string {
  return "my check always passes!"
}
 
type MyModule struct{}
 
func (m *MyModule) Check() Check {
 return new(MyCheck)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions